Linux Command learning: cut, linux Command cut
The cut command is also one of the most common commands in linux.
As its name suggests, cut is used to cut data. Specifically, cut data is used in files. Cut is a processing object for each row. This mechanism is the same as sed.
There are three cut measurements for the cut command:
In addition, the cut command also supports the range represented by numbers,
N n'th byte, character or field, counted from 1
N-from n' th byte, character or field, to end of line
N-M from N 'th to m' th (bounded DED) byte, character or field
-M from first to m' th (bounded DED) byte, character or field
For example:
Cut by byte
Date | cut-B 1-5
2014
Date | cut-B 1-6
2014
Date | cut-B 1-7
2014
From the example above, we can see that the Chinese character "year" occupies three bytes.
Cut by character
Date
Friday, October 10, 2014 14:48:16 CST
Date | cut-c 1, 3, 4
214
Multiple positioning locations are separated by commas (,).
Cut by domain
Date
Friday, October 10, 2014 14:46:09 CST
Date | cut-d ""-f 4, 5
14:46:12 Friday
-D indicates the delimiter and the delimiter must be a single character.
Reference: http://www.cnblogs.com/xianghang123/archive/2011/12/06/2277531.html
Learn how to use linux commands in practical use
Linux shell is far from windows cmd. There are two examples below:
Search for keywords to kill processes in batches. Here, all processes with python keywords are killed:
Ps-ef | grep "python" | awk '{print $2}' | xargs kill-9
Decompress the gz log files in batches. Assume that the directory contains the following compressed files:
Log.2.gz
Log.3.gz
Log.4.gz
...
Log.100.gz
There are other miscellaneous files
Log.1
. Svn
Ls | grep "log" | grep "gz" | sed "s #. * # gunzip & #" | sh-x
Cut in Linux commands
Usage: cut-cnum1-num2 filename Description: displays the text from the beginning of each line num1 to num2. Example: shell> cat example test2 this is test1 shell> cut-c1-6 example # count the first six characters starting with print from 1 test2 this I can split a row into multiple columns, use-d': 'To change the separator :. Then use-f n to specify the selected columns. For example, $ echo 12:00:01 | cut-d': '-f 2 00 Cut () function cut the selected content in the edit box of the current row and column of the data window control and save it to the system clipboard, for a RichText data window, cut the selected content from the data window control to the system clipboard syntax dwcontrol. cut () parameter dwcontrol data window control name-B, -- bytes bytd-list: Only output bytes in the byte-list interval, TABs and backspaces both occupy 1 byte. [1]-c, -- characters character-list: only the TABs and backspaces characters in the character-list are output. -F, -- fields field-list: only the fields in the field-list are output. -D, -- delimiter delim: Specifies the field-list delimiter in the-f parameter (the first character in delim, and the default is TAB ). -N: do not separate multiple bytes. -S, -- only-delimited: The-f parameter does not output rows without domain delimiters. -- Help: Output help information on the standard output and exit. -- Version: output the version information on the standard output and exit. Return the number of characters to be cut when the Long function is successfully executed. If no content is selected in the editing control, no characters are cut. The function returns 0. If the function is executed incorrectly,-1 is returned, if the value of dwcontrol is NULL, the Cut () function returns NULL () you can also copy the selected content by pressing Ctrl + X or the mouse on the keyboard. You can use the data window control object function in the code.