Summary awk command of 1

awk, grep, sedAre linuxthree weapon manipulate text, but also must master linuxone command. Three functions are working with text, but the focus is different, which is a awkmost powerful but also the most complex. grepOr simply to find more suitable for matching text, sedis more suitable for matching to edit the text, awkis more suitable for formatted text, the text is more complex formatting.

All of the following experiments output, are test file test.logcontents as a benchmark:

20170102 admin,password Open
20170801 nmask,nmask close
20180902 nm4k,test filter

AWKIs a language processing text files, text analysis is a powerful tool;  awkis listed as the division count, $0represents all the columns, $1the first column, $2the second column.

awk parameters

  • -F Input file specifies off separators, such as -F:
  • -v Assigning a user-defined variable, such as-va=1
  • -f Read from a script file awkcommand

NOTE: only lists the most common parameters

Separator

Dividing each row by row space, and outputs the first and the third column

Awk $ '$ {Print. 1,. 3} $ ' the test.log
 # or  $ CAT the test.log | awk '{. 1 Print $, $}. 3 '

Custom delimiter

Use "," segmentation, parameters -F

awk -F, '{print $1,$2}' test.log

A plurality of separators, first dividing spaces, and then dividing the result re-use "," split

Awk -F $ '[,] '   '. 1 {Print $, $ 2, $}. 3 ' the test.log have a space before the comma Note #

Guess you like

Origin www.cnblogs.com/guo-s/p/12543051.html