gerp find, sed editor, awk analysis and processing according to the content of the action

awk (Keyword: Analysis & Processing)  analysis processing line by line awk 'operation conditions of the type {1 1 2} {type operation condition 2}' filename, awk standard input may be read from the previous instruction
with respect to the often used sed to process an entire row, awk tend row among the plurality of divided "field" (area) in the default delimiter is a tab key or a spacebar
example:
Last -n. 5 | awk '{$. 1 Print "\ T "$ 3} 'here braces $. 1" \ t "without spaces between $ 3 may be, but should add spaces, also note that" \ t "is a double quotation marks, because of their own content in a single quotes
$ 0 represents the entire line of $ 1 for the first area, and so on
awk treatment process is:
1. read the first line, the first line of data to fill variables $ 0, $ 1 ... and other variables in
2. accordance with conditions limiting operation performed by
3. next to the next line
so that, once the AWK is a line process, and a minimum unit in the processing region is a
plus three variables, NF: number of fields in each row processing, NR section to the present processing current lines delimiter FS
logic determines> <> = <= == assignment directly =!
CAT / etc / the passwd | awk '{FS = ":"defined first separator is: and determining, note is determined not written in {}, and then perform an action, FS = " : "this is an action, the assignment action, not a judge,
The END BEGIN, programmers and finishing an initialization operation, the operation will be performed are listed after BEGIN {} in the beginning before awk scanned input, operates in the END {}, is executed after the input document has been scanned.
Awk line number '/ test / {print NR} ' abc the row with the test print, a regular expression can be noted between //
awk within {}, may be used if else, for (i = 0 ; i < 10; i ++), i = 1 while (i <NF)
can be seen, the use of many awk are equivalent to the C language, such as "\ t" delimiter, Print format, if, while, for the like

awk is a rather complex tool, the real use, and then add it. (picture related tools)

 

sed (Keyword: edit)  text editor sed in units of file can be modified directly, but generally do not recommend it, you can analyze standard input
basic work: sed [-nef] '[action]' [input text]
- n: quiet mode, sed general usage, data from stdin will generally be listed on the screen, use the -n parameter if, and only after that line sed process is listed.
-e: multiple editing, such as you at the same time want to delete a row, want to change the other line, you can '1,5d' -e 's / abcwith the -e sed
-f: first sed action written in a file, and then by sed -f scriptfile sed can perform direct actions within scriptfile (no experiment was a success, not recommended)
-i: direct editing, this time is to really change the contents of the file, and others are just changing the display (no. recommended)
action:
a new, a can take back the string, and this string will appear on a new line (next line).
substituted c, c behind the strings that can be substituted n1, n2 between line
d deleted, do not take anything behind
i inserted after String will appear on a line
p printing selected information listed, and generally with sed -n operating sed -n '3p' only the print line. 3
S substituted, substituents similar to the vi, 1,20s / old / new / g

[Line-address] q quit, exit matched to a line, to improve efficiency

[Line-address] r is matched to the line reading a file, for example: sed '1r qqq' abc, note that the text is written in a write behind the first row, the second row is

[Line-address] w file, matching row writing a file to example: sed -n '/ m / w qqq' abc, abc read with m rows from the write qqq file, note that the write with coverage.


For example:
sed '1D' abc abc delete the first line in the file, note that at this time will show all lines except the first line, because the first line has been deleted (the actual files are not deleted, but only when the display has been deleted)
sed -n '1D' abc what is not displayed, because after treatment sed row, delete operation is so unrealistic.
sed '2, D $' abc abc deleted from the second row all to the last line of content, note that the $ sign regex end of the line said, but did not say where the end of the line, it will refer to the end of the last line, ^ beginning, the beginning of what you do if you do not specify, then that is the first line beginning
sed '$ d' abc only delete the last line, because did not specify whether the end of the line, that it is the last line of the end
sed '/ test / d' abc file all rows with a test, and delete all
sed '/ test / a RRRRRRR 'abc RRRRRRR appended to the next line with all the test row by row may also Sed' 1,5c RRRRRRR 'ABC
Sed' / test / C RRRRRRR 'ABC will replace all of the rows with a test RRRRRRR, of course, here may be replaced by a line, such as sed '1,5 c RRRRRRR 'abc



grep (Keyword: Interception)  text gathering tools, combined with the regular expression is very powerful
main parameters []
-c: Only output matching rows
-I: case-insensitive
-h: do not display the file name when querying multiple file
-l: query multiple files, only the name of the output file containing the matching character
-n: display the line number and line matching
-v: displays all line does not contain matching text (I often use grep to remove itself)
basic work: grep to match content file name, for example:
grep 'test' d * show all rows in the file begins with d-contained test of
grep 'test' aa bb cc line containing test in aa bb cc file
grep '[az] \ {5 } \ 'aa displays all strings comprising at least 5 contiguous string lowercase

 

Turn ( https://blog.csdn.net/technologyleader/article/details/81945069 )

Guess you like

Origin www.cnblogs.com/isme-zjh/p/11387257.html