Common tools for Linux text processing

Source: Internet
Author: User
Tags add numbers processing text

650) this.width=650; "title=" clip_image001[6] "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px; margin:0px; padding-right:0px "border=" 0 "alt=" clip_image001[6] "src=" http://s3.51cto.com/wyfs02/M01/85/91/ Wkiom1eondyrxjxaaaayxdyttg0996.png "" 244 "height="/>

650) this.width=650; "title=" clip_image002[6] "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px; margin:0px; padding-right:0px "border=" 0 "alt=" clip_image002[6] "src=" http://s3.51cto.com/wyfs02/M02/85/91/ Wkiom1eond2dljltaaar1aucj1m444.png "" 244 "height="/>

CTRL + Z Pause

650) this.width=650; "title=" clip_image004[4] "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px; margin:0px; padding-right:0px "border=" 0 "alt=" clip_image004[4] "src=" http://s3.51cto.com/wyfs02/M02/85/91/wKiom1eonEDR6_ 48aaazcyaqgti567.jpg "" 244 "height="/>

gpasswd-d Test ZU1

or USERMOD-G student test to add a secondary group (overwrite) from a new definition

[Email protected] ~]# gpasswd--help

-A,--add user add user to GROUP

-D,--delete user remove user from GROUP

-R,--remove-password remove the GROUP ' s password

-R,--restrict restrict access to GROUP to it members

-M,--members USER,... Set the list of members of GROUP

-A,--administrators ADMIN,...

Set the list of administrators for GROUP

$ (command) execute the $ command and perform command substitution

650) this.width=650; "title=" clip_image006[4] "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px; margin:0px; padding-right:0px "border=" 0 "alt=" clip_image006[4] "src=" http://s3.51cto.com/wyfs02/M00/85/90/wKioL1eonELC2_ O1aaavv3ocdam797.jpg "244" height= "Max"/>

`` Inverted single quotation marks Command substitution

650) this.width=650; "title=" clip_image008[4] "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px; margin:0px; padding-right:0px "border=" 0 "alt=" clip_image008[4] "src=" http://s3.51cto.com/wyfs02/M01/85/90/ Wkiol1eonekihz-oaaao9hrxg5s885.jpg "" 244 "height="/>

Cat ( - N ), TAC , Head ( - N ), Tail ( - N , - F )

tailf/var/log/messages Listening Logs

More , Less , grep

Cut sort Uniq

Text Processing instructions:

650) this.width=650; "title=" clip_image010[4] "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px; margin:0px; padding-right:0px "border=" 0 "alt=" clip_image010[4] "src=" http://s3.51cto.com/wyfs02/M02/85/90/ Wkiol1eonewd8yw4aaatho5lygo138.jpg "" 244 "height=" 104 "/>

Cat-n add numbers, process blank lines

- b Add number blank line not not processed Add line number

650) this.width=650; "title=" clip_image012[4] "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px; margin:0px; padding-right:0px "border=" 0 "alt=" clip_image012[4] "src=" http://s3.51cto.com/wyfs02/M00/85/90/ Wkiol1eonejtx0zzaaaqira-2e0044.jpg "" 244 "height="/>

-A show line breaks

650) this.width=650; "title=" clip_image014[4] "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px; margin:0px; padding-right:0px "border=" 0 "alt=" clip_image014[4] "src=" http://s3.51cto.com/wyfs02/M01/85/91/ Wkiom1eonenynp6saaawl1_ppds439.jpg "" 244 "height="/>

-T only displays the TAB key ^i

-e only shows carriage return line break $

650) this.width=650; "title=" clip_image015[8] "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px; margin:0px; padding-right:0px "border=" 0 "alt=" clip_image015[8] "src=" http://s3.51cto.com/wyfs02/M02/85/91/ Wkiom1eonenivrybaaaazy0iwxq872.png "" 213 "height="/> Reverse output display

Avoid using cat to view binary files (a bunch of garbled characters), avoid the bird, reset or Tset reset (playing is also garbled), will clear garbled

650) this.width=650; "title=" clip_image017[4] "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px; margin:0px; padding-right:0px "border=" 0 "alt=" clip_image017[4] "src=" http://s3.51cto.com/wyfs02/M00/85/90/ Wkiol1eonevtoftpaaaj5aukdsg878.jpg "" 244 "height="/>

Force monitoring file changes (can be used as a monitoring system log)

650) this.width=650; "title=" clip_image018[8] "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px; margin:0px; padding-right:0px "border=" 0 "alt=" clip_image018[8] "src=" http://s3.51cto.com/wyfs02/M02/85/90/ Wkiol1eone2g1ufhaaavzlypbqe740.png "" 196 "height=" "/> ctrl-c exit

displaying 10-15 rows of information

650) this.width=650; "title=" clip_image020[4] "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px; margin:0px; padding-right:0px "border=" 0 "alt=" clip_image020[4] "src=" http://s3.51cto.com/wyfs02/M01/85/90/ Wkiol1eonfhipxeiaabjkxg7m38517.jpg "" 244 "height=" 173 "/>

650) this.width=650; "title=" clip_image022[4] "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px; margin:0px; padding-right:0px "border=" 0 "alt=" clip_image022[4] "src=" http://s3.51cto.com/wyfs02/M02/85/91/ Wkiom1eonfphq3jpaaa1p6mz_ay376.jpg "" 244 "height=" 122 "/>

# tail-n-7 Fstab | Head-n Fstab

650) this.width=650; "title=" clip_image023[4] "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px; margin:0px; padding-right:0px "border=" 0 "alt=" clip_image023[4] "src=" http://s3.51cto.com/wyfs02/M01/85/90/ Wkiol1eonfwy1xvhaack90zg9io444.png "" 244 "height=" 215 "/>

650) this.width=650; "title=" clip_image025[4] "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px; margin:0px; padding-right:0px "border=" 0 "alt=" clip_image025[4] "src=" http://s3.51cto.com/wyfs02/M02/85/91/ Wkiom1eonfew32spaaatzezpiso383.jpg "" 244 "height="/>

650) this.width=650; "title=" clip_image027[4] "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px; margin:0px; padding-right:0px "border=" 0 "alt=" clip_image027[4] "src=" http://s3.51cto.com/wyfs02/M00/85/91/ Wkiom1eonfjaktstaaathacb53o946.jpg "" 244 "height="/>

grep is handled as a unit of action, and a match will be displayed.

650) this.width=650; "title=" clip_image029[4] "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px; margin:0px; padding-right:0px "border=" 0 "alt=" clip_image029[4] "src=" http://s3.51cto.com/wyfs02/M00/85/91/ Wkiom1eonfrs97exaaamjjzrjbw634.jpg "" 244 "height="/>

650) this.width=650; "title=" clip_image031[4] "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px; margin:0px; padding-right:0px "border=" 0 "alt=" clip_image031[4] "src=" http://s3.51cto.com/wyfs02/M01/85/91/ Wkiom1eonfuwflucaaaqyxcq3no364.jpg "244" height= "Notoginseng"/>

--color=auto Automatically add color

650) this.width=650; "title=" clip_image033[4] "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px; margin:0px; padding-right:0px "border=" 0 "alt=" clip_image033[4] "src=" http://s3.51cto.com/wyfs02/M01/85/91/ Wkiom1eonfytv7fgaaaret5pmmi712.jpg "" 244 "height="/>

-W Word

650) this.width=650; "title=" clip_image034[4] "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px; margin:0px; padding-right:0px "border=" 0 "alt=" clip_image034[4] "src=" http://s3.51cto.com/wyfs02/M01/85/90/ Wkiol1eonfyxkbb-aaaswehapl8373.png "" 244 "height=" "/>

-N plus the line number of the original

650) this.width=650; "title=" clip_image035[4] "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px; margin:0px; padding-right:0px "border=" 0 "alt=" clip_image035[4] "src=" http://s3.51cto.com/wyfs02/M02/85/90/ Wkiol1eonf3bw-ahaaanjkwajyw002.png "" 244 "height="/>

-an

-bn

650) this.width=650; "title=" clip_image037[4] "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px; margin:0px; padding-right:0px "border=" 0 "alt=" clip_image037[4] "src=" http://s3.51cto.com/wyfs02/M02/85/90/ Wkiol1eonggx3boraaa9dnggp0q855.jpg "" 244 "height=" 108 "/>

Search for content that begins with ' ^ keyword '

650) this.width=650; "title=" clip_image038[4] "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px; margin:0px; padding-right:0px "border=" 0 "alt=" clip_image038[4] "src=" http://s3.51cto.com/wyfs02/M01/85/91/ Wkiom1eongkauy3vaaaamvzxdu0941.png "" 244 "height="/>

Search for content that ends with ' keyword $ '

Third, Cut sort Uniq

Cut Process as field (field)

- D < > what to use as a segmented symbol

- F show the first paragraph

- C Intercept characters

650) this.width=650; "title=" clip_image039[4] "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px; margin:0px; padding-right:0px "border=" 0 "alt=" clip_image039[4] "src=" http://s3.51cto.com/wyfs02/M01/85/90/ Wkiol1eongljdgkiaaau3hiluyq750.png "" 244 "height="/>

Sort Sort

Sort by character order by default (ASCII code)

- N Sort by number size

- R reverse Order

- u Call Uniq Delete repeating section, only one row for the same type

Uniq to delete duplicate rows on the output

- C How many times the repetition occurs (statistics)

- u only one occurrence is retained, the number of times is 2 times included 2 Times above Delete, remove duplicate lines completely-D

- D Number of reservations at 2 times included 2 more than a second content

650) this.width=650; "title=" clip_image041[4] "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px; margin:0px; padding-right:0px "border=" 0 "alt=" clip_image041[4] "src=" http://s3.51cto.com/wyfs02/M00/85/90/ Wkiol1eongocz33iaaaqgz6sw8a285.jpg "" 244 "height="/>

Overall Practice:

cut-d :-f2

- D : To: is a delimiter. -f2 Show second column

cut-d ' Space '-f1

- D ' ' Take a space as a delimiter-f1 Show second column

650) this.width=650; "title=" clip_image043[4] "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" clip_image043[4] "src=" http://s3.51cto.com/wyfs02/M02/85/90/wKioL1eonGXg-qB_ Aaamyksmbhm041.jpg "" 244 "height="/>

Text Processing Instructions

First, cat head tail

Cat Read text file contents

- N display content and add line number, empty line also add number

- b display content and add line number, blank line number is not added

- e Show file Carriage return newline character $

- T Display the tab in a file Key ^i

-A Show file carriage return line break and tab Key

for Cat Accidentally read to the binary file screen is garbled, enter

Reset , reinitialize the terminal, if not normal, enter Tset instruction

Head the first 10 lines of the file are read by default and displayed

-N,--lines=[-]k print the first K lines instead of the first 10;

With the leading '-', print all and the last

K lines of each file

Tail display the last ten lines of a file by default

-N,--lines=[-]k output the last K-lines, instead of the last 10;

or use-n +k to output lines starting with the Kth

tail-f/var/log/messages Monitoring System log files

Tailf/var/log/messages

combined with pipeline Directive, display Fstab 第10-15 of the file Line:

Tail-n +10 fstab |head-n 6 or

Tail-n +10 fstab |head-n 6

Second, more less grep

More display files on a page-by-page basis

More file The space represents the next screen of content, carriage return on behalf of the next line of content

Q represents the exit. Do not support back reading

Less-is-a program similar-to-more (1), but which allows backward movement

In the file as well as forward movement

Less file The space represents the next screen content, the carriage return represents the next line of content, the arrow keys, PgUp pgdn all support hold

Q represents the exit. Supports back-reading and supports the V - shortcut Call VI Edit the text being read

grep print lines matching a pattern

grep root/etc/passwd

--color=auto The matching sections are highlighted

- W the target of a search is a word, not a string

- I. Ignore case when searching

- N Displays the line number of the searched content in the original file

-an from the search to the line calculation, and then additional display n Line

-bn from the search to the line calculation, and then the additional display n Line

- v exclude the specified search content

^# Search by # line at the beginning, General # begins in the configuration file, indicating the comment

.$ search for. End of Line

^$ Search for Blank lines

Three, cut sort Uniq

Cut Cut out selected fields of each line of a file

Sort sort lines of text files

Uniq report or filter out repeated lines in a file

Synthesis: cut-d:-f7/etc/passwd | Sort | Uniq

Cut processing text content on the output, the source file has not changed

- D the symbol followed by the sub-field

- F Select the first few fields

-c1-5 selectively one to fifth characters

Sort

Default photo characters ordered, source file not changed

- N Sort by number size

- R reverse Order

- u Call Uniq Delete repeating section, only one row for the same type

Uniq

Delete duplicate rows on output, the source file does not change

- u keep only the content that appears once, usually with sort Use

- D only the content that appears twice and above is retained, generally with the sort Use

- C number of statistical occurrences

added: $ (command) " command Substitution

Echo "My hostname is: $ (hostname), and my working is: ' PWD ' "

Common tools for Linux text processing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.