The purpose of the tool is to read the text file line-by-row, then slice the read-in text (by default, separated by a space), and then read it to the next line, which is already available. is a format report generation tool that is then used to process text.
Currently, the awk used on linux is gawk(open source awk), abbreviated to Awk.
Usage:
#awk [Options] ' script ' file,file2,... #awk [options] ' PATTERN {action} ' filelist
quoted words, each line from $ Start, $ As the current line, ending with a newline character as the line
commonly used for: awk ' {print$1} ' File
Common options:
- F : Specify field separators awk-f: ' {print '} '/etc/passwd
- V: assigning an initial value to a variable
print function, printing content, with line break
The printf function, which formats the printed content without line breaks, requires the following format:
awk ' {printF ' format ' $} ' file
The format is as follows:
in % begins with a character followed by a
%c Display character ASCII code%d,%i: decimal number%e,%e scientific notation display numerical%g,%g scientific notation format or floating-point format display numeric value%f display floating-point number%u unsigned integer percent display% self%s display string
Modifier
N, such as%10s, the current string occupies 10 cells, not enough to fill empty-: left-aligned, default right-aligned +: Display numeric symbols
Example
Linux1:/home/test #awk ' {printf '%-15s%i\n ", $1,$2} ' 1welcome 0hello 0
Output redirection
Printitems > Output-file
Printitems >> Output-file
Printitems | Command
Special file descriptors
/dev/stdin: Standard input
/dev/stdout Standard Output
/dev/stderr : Error Output
/dev/fd/n a specific file descriptor, such as /dev/stdin is equivalent to /dev/fd/0
For example:
Linux1:/home # awk-f: ' {printf '%-15s%i\n ',$1,$3> '/dev/stderr '} '/etc/passwdroot 0bin 1daemon 2LP 4mail 8games 12wwwrun 30ftp 40nobody 65534
This article is from the "testing of the Rhythm" blog, please be sure to keep this source http://fociceo.blog.51cto.com/2480/1664449
Some tips for using the Linux awk command-basic commands