Linux pipeline command note, linux pipeline command note
Pipeline command (pipe)
Use "|" to define the symbol
Pipeline commands must be able to receive data from the previous command into standard input to continue processing
1. Select the command: cut, grep. Analyze the data and retrieve what we want.
-Cut refers to a piece of information that is "cut" and taken out in the unit of "row.
Cut-d 'separator '-f fields is used for delimiter classes (-f fields retrieves the meaning of the nth segment-f 5 fifth segment-f 3,5 third and fifth segments)
The cut-c character range is used to arrange neatly and formatted Information (-c range, which extracts fixed cut-c 12-20 in characters)
-Gerp analyzes a line of information, including the required information, and takes the entire line out.
Grep [-acinv] [-- color = auto] 'query string' filename
-A: query the data of a binary file as a text file.
-C: calculates the number of times a string is found.
-I: case insensitive
-N: Output row number
-- Color = auto: color of keywords
Example: last | grep 'root'
Last | grep 'root' | cut-d' f1
2. Sorting command sort, wc, uniq
-Sort is sorted based on different data types.
Sort [-fbMnrtuk] [file or stdin] (-n uses pure numeric sorting-r reverse sorting-only one row of data with the same u-t separator-k interval)
Example: cat/etc/passwd | sort-t': '-k 3-n
-Uniq repeated Data Processing
Uniq [ic]
-I case-insensitive
-C for counting
Example: last | cut-d ''-f1 | sort | uniq
-Number of lines, characters, and words in the wc statistics File
Wc [-lwm]
-L: Line
-W: Word
-M: character
Example: cat/etc/man. config | wc
3. Dual-targeting tee transfers a copy of the standard out to the file and transfers the same data to the screen for processing.
Example: ls-l/home | tee ~ /Homefile | more
4. character conversion commands: tr, col, join, paste, expand
-Tr: delete or replace the text in the information.
Tr [-ds] set1 (-d Delete-s replace)
Example: last | tr' [a-z] ''[A-Z]''
Cat/etc/passwd | tr-d ':'
-Col [-xb]: replace tab with Space
-Join is used to process data between two files. Before using join, sort by sort first.
Join [-ti12] file1 file2
-T: Data delimiter. The default value is space.
Example: join-t': '-1 4/etc/paswd-2 3/etc/group
-Split cut command
Split [-bl] file PREFIX
-B: size of the file to be cut
-L cut by number of rows
Example: ls-al/| split-l 10-lsroot
Wc-l lsroot *