Cut: Each line of the file cuts bytes, characters, and fields and writes those bytes, characters, and fields to standard output. If you do not specify a File parameter, the Cut command reads standard input. One of the-B,-C, or-f flags must be specified. Main parameters:-B (Byte): Split in bytes, one space for one byte, three bytes for a Chinese character,-C (char): Split in characters, Chinese characters and spaces are counted as one character;-D: Custom delimiter, default to tab, to use with-f when an empty When the lattice is a separatorenclose the space in double or single quotation marks;-F (field): Used with-D to define which area to display;-N: Cancels splitting multibyte characters. Used only with the-B flag. If the last byte of the character falls within the range of <br/> indicated by the List parameter of the-B flag, the character is written out;the character will be excluded. Command usage: cut-b list [-n] [file ...] CUT-C list [File ...] Cut-f list [-D delim][-s][file ...] List represents the-B,-C,-f operation range,-n often represents a specific number, file represents the nature of the text file to manipulate the name, file represents the nature of the text file to manipulate the name;-S to exclude those lines that do not contain delimiters (this facilitates the removal of comments and headings);
in the above three ways, the bytes are extracted from the specified range (-B), or the character (-c), or the word
segment (-f). Example: 1, [[email protected] ~]#Date |cut-b 1-4: Divides the current date by bytes, and takes the first 4 bytes of the current date; 2, [email protected] ~]#echo "2,1,3,2,5" | cut-d,-f1: Press "," to Split "2,1,3,2,5" string, take the first field of the string; output: 2 3, [[email protected] ~]#echo "2,1,3,2,5" | cut-d,-f1-: Press "," to split the string,from the 1th field to the end, the result will be separated by a "," field;Output: 2,1,3,2,5 4, [[email protected] ~]#echo "2,1,3,2,5" | cut-d,-f1-3: Press "," to split the string,from the 1th field to the 3rd field, the result is separated by a "," field;Output: 2,1,3 5, [[email protected] ~]#echo "2,1,3,2,5" | cut-d,-f1-3,5: Press "," to split the character,from the 1th field to the 3rd and 5th fields, the resulting fields are separated by ",";Output: 2,1,3,5 6, [[email protected] ~]#echo "2,1,3,2,5" | cut-d,-f-3: Press "," to split the character, take1th to 3rd fields, the result of the field will be separated by ",";Output: 2,1,3 7, [[email protected] ~]#echo "2,1,3,2,5" | cut-d,-f5,1-2: Press "," to split the wordfrom the 1th field to the 2nd and 5th fields, the resulting fields will be separated by ",". Cut will firstall the positions after-B are sorted from small to large, and then extracted;Output: 2,1,3,5 8, [[email protected] ~]#echo "2,1,3,2,5" | cut-d,-f-2,4-: Press "," to split the character,take the 1th field to the 2nd and 4th to the last, and the result is separated by "," between the fields. Output Result: 2,1,2,5
what are the defects and deficiencies of cut: if some fields in the file are separated by a few spaces,
Cut is a bit of a
hassle, because cut is only good at dealing with "a single character"
text content.
The cut of Linux commands