Special symbols
Cut
Sort
Wc
Uniq
Tee
Tr
Split
Special symbols
* Any of the characters? Any one character # comment character \ de-semantic character | Pipe character
Cut
The Cut command is used to display the specified part of the row, deleting the specified field in the file. Cut is often used to display the contents of a file
Usage:
Cut parameter file (specifies the file to be filtered for content)
Parameters:
-B: Displays only the contents of the direct range specified in the row;-C: Displays only the characters of the specified range in the row;-D: Specifies the delimiter for the field, the default field delimiter is "tab";-F: Displays the contents of the specified field;
Instance:
[email protected] text]# cat test.txt No Name Mark Percent01 Tom 9102 Jack 8703 Alex 68 98 extracts the specified field using the-F option: [[Emai L protected] text]# cut-f 1 test.txt no010203[[email protected] text]# cut-f2,3 test.txt Name marktom 69jack 71alex 68 use The-D option specifies the field delimiter: [[email protected] text]# cat test2.txt No; Name; Mark; percent01;tom;69;9102;jack;71;8703;alex;68;98 [[email protected] text]# cut-f2-d ";" Test2.txt Nametomjackalex
Specify the character or byte range of the field:
The cut command can display a string of characters as columns: N-bytes, characters, fields to the end, N-m: bytes, characters, fields from Nth Byte, character, field to M (including M), character, field, and-M: bytes, characters, and fields from the 1th byte, character, field to the first (including m). Above is notation, combined with the following options to touch a range of bytes, characters are specified as a field:-B for the byte;-C for the character;-F for the definition field.
Example
[[email protected] text]# cat test.txt abcdefghijklmnopqrstuvwxyz print 1th to 3rd characters: [[email protected] text]# cut-c1-3 Test.txt ABC print the first 2 characters: [[email protected] text]# cut-c-2 test.txt ab printing starts from the 5th character to the end: [[email protected] text]# CUT-C5-TEST.TX T efghijklmnopqrstuvwxyz
Sort
Sort the files and output the sort results standard
Usage:
Sort parameter file (specifies the list of files to be sorted)
Parameters:
-B: Ignores the space character that starts at the beginning of each line;-C: Checks if the file is sorted in order;-D: When sorting, the letters, numbers, and whitespace characters are processed, and other characters are ignored;-f: When sorting, lowercase letters are treated as uppercase letters;-N: Sort by numeric size ;-R: Sorts the;-t< delimited characters in reverse order;: Specifies the field separator character to use when sorting;
Instance:
Sort compares each line of a file/text as a unit, comparing it from the first character backwards, to the ASCII value in turn, and finally outputting them in ascending order. # Cat sort.txtaaa:10:1.1ccc:30:3.3ddd:40:4.4bbb:20:2.2eee:50:5.5eee:50:5.5# Sort SORT.TXTAAA:10:1.1BBB:20:2.2CCC : 30:3.3ddd:40:4.4eee:50:5.5eee:50:5.5
Ignore the same row using the-u option or Uniq:
# cat sort.txtaaa:10:1.1ccc:30:3.3ddd:40:4.4bbb:20:2.2eee:50:5.5eee:50:5.5# Sort-u SORT.TXTAAA:10:1.1BBB:20:2.2CCC : 30:3.3ddd:40:4.4eee:50:5.5 or # Uniq sort.txtaaa:10:1.1ccc:30:3.3ddd:40:4.4bbb:20:2.2eee:50:5.5
Use of the-N,-R,-K,-t options for sort:
# cat sort.txtaaa:bb:ccaaa:30:1.6ccc:50:3.3ddd:20:4.2bbb:10:2.5eee:40:5.4eee:60:5.1# arranges the BB column in order from small to large in numbers: # Sort-nk 2-t : sort.txtaaa:bb:ccbbb:10:2.5ddd:20:4.2aaa:30:1.6eee:40:5.4ccc:50:3.3eee:60:5.1# the CC column numbers from large to small order: # SORT-NRK 3-T: Sort.txteee:40:5.4eee:60:5.1ddd:20:4.2ccc:50:3.3bbb:10:2.5aaa:30:1.6aaa:bb:cc#-N is sorted by numeric size,-R is in reverse order,- K is the field that specifies the sort of love you want,-t specifies that the field delimiter is a colon
Wc
The WC command is used to calculate numbers. With the WC instruction we can calculate the number of bytes, words, or columns of a file, if the file name is not specified, or if the given file name is "-", the WC instruction reads the data from the standard input device.
Usage:
WC parameter file (list of files to be counted)
Parameters:
-C: Displays only the number of bytes;-L: Only the number of columns is displayed;-W: Displays only words.
Uniq
The Uniq command is used to report or ignore duplicate rows in a file and is typically used in conjunction with the sort command
Usage:
Uniq parameter input/output file
Parameters:
-C: Displays the number of occurrences of the row next to each column;-D: Displays only the rows that appear repeatedly;
Instance:
Delete duplicate rows: Uniq file.txtsort file.txt | Uniqsort-u File.txt only one line is displayed: Uniq-u file.txtsort file.txt | Uniq-u count the number of times each line appears in a file: sort file.txt | Uniq-c finding duplicate lines in a file: sort file.txt | Uniq-d
Tee
The tee command is used to redirect data to a file and redirect the data to a given file and screen.
Usage:
Tee parameter file (specifies the output redirected file)
Parameters:
-A: Use Append mode when redirecting to file;
Tr
The TR command can replace, compress, and delete characters from standard input. It can turn a set of characters into another set of characters
Split
Split a large file into many small files
Parameters:
-B: The value is the size of each output file, in bytes. -L: The value is the size of the number of columns per output file. -D: Use a number as a suffix.
Instance:
The generates a test file of size 100KB: [[email protected] split]# dd if=/dev/zero bs=100k count= 1 of=date.file1+0 records in1+0 records out102400 bytes (102 kB) copied, 0.00043 seconds, 238 mb/s Use the split command to split the Date.file file created above into a small file of size 10KB: [[email protected] split]# split -b 10k date.file [[email protected] split]# lsdate.file xaa xab xac xad xae xaf xag xah xai xaj
The file is split into multiple suffix files with letters, and if you want to use the-D parameter with a numeric suffix, you can specify the length of the suffix by using-a length: [[email protected] split]# Split-b 10k date.file-d a 3[[ Email protected] split]# lsdate.file x000 x001 x002 x003 x004 x005 x006 x007 x008 x009 Specifies the prefix of the file name for the split files: [email Protected] split]# Split-b 10k date.file-d A 3 split_file[[email protected] split]# lsdate.file split_file000 split_ file001 split_file002 split_file003 split_file004 split_file005 split_file006 split_file007 split_file008 Split_fi le009
Linux Shell Basics-3