(Ix) character processing command

1: cut [options] filename

Options:

-f column number: Extraction columns

-d Separator: Separator divided column as specified

-c character range: not dependent delimiters to distinguish a column, but by the character extracted by the range field (the first row is 0). "N-" represents the n-th character to the end of the line; "nm" from the n m-th character to character; "- m" represents the character from the first to the m-th character. The default delimiter is a tab cut command, which is the "tab" key.

 

3, but

sed is mainly used to select the data, replace, delete, add commands.

The file is not directly modify the command vi to edit.

    -n: General sed command all data will be output to the screen, if you join this select, only the line will go through to the screen sed command processing.

-e: allows multiple applications sed command to edit the input data.

-f script file name: From sed sed script read operation. and awk -f command is very similar.

-r: support extended regular expressions in sed.

-i: modified with the modification result sed file read data directly, rather than by the screen output operation:

a \: Append, add one or more lines after the current line. Add multiple lines, except for the last line, the end of each row need to use "\" represents the data is not the end.

c \: row replacement and the original data with a row behind string c, replacing multiple rows, except the last, the end of each line required "\" represents the data is not the end.

i \: inserting, before inserting one or more rows in the current period. Insert multiple rows, except for the last line, the end of each row need to use "\" represents the data is not the end.

d: Delete to delete the specified

p: print, export specified line.

s: string replacement, replacing a character string with another string. The format of "line range s / old string / new string / G" (and similar substitution pattern in vim)

Sed modification made does not directly change the contents of the file (if the output command received by pipe, the documents are not even this case), but rather only the modifications to the screen, unless the "-i "options are directly modify the file.

 

example:

(1) operative

sed '2p' student.txt screen display 2 rows of data

(2) Only the second line of the display displays only -n

sed -n '2p' student.txt

(3) 2,4 delete rows of data

sed '2,4d' student.txt

(4) add the specified string behind the second row

sed '2a  ddddddd' student.txt

(1) add a string developed in front of the second row

sed "2i heeeeeee"  student.txt

(2) The first line is replaced with #

sed '4s/^/#/g' student.txt

 

3 : character processing command

(1) Sort sort command

-f: ignore case

-b: Ignore blank portion of the front of each row

-n: numeric order sort, sort // default string values ​​SortingUse

-r: reverse sequencing

-u: remove duplicate rows. It is uniq command

-t: Specifies delimiter, default delimiter is a tab

-kn [, m]: sorted according to fields specified range. From the first field n, m end of the field (to the end of the line by default)

sort -n -r student.txt // value in descending order according to the character

sort -n -t ":" -k 3,3 /etc/passwd

Of course, "-k" option can be used directly "-k 3", the representative from the third field to the end of the line are the sort (the first character to sort, if agreed, the second character reordering know end of the line).

(2) uniq removing duplicate rows

 

(3) statistical wc command

   wc -l count the number of lines

Guess you like

Origin www.cnblogs.com/love-life-insist/p/11668813.html