1. awk obtains the specified item in the file: The system reads a row of data and determines the specific item based on the "$" matching number. Then, it continues to read the next row until the end of the file.
For example:
Awk '{print $2}' awktest. Print the second character.
Awk '{print $2}' awktest> tt.txt. The default Delimiter is space. The system searches for spaces and finds that the character between the first non-space character and the next space character is the second one.
Awk-F', ''{print $2} 'awktest> tt.txt. Use ',' as the separator to retrieve the first field behind 'and.
Awk-F', ''{print $2} 'awktest | tee tt.txt writes the obtained content to tt.txt and outputs it on the screen. (TEE command: It transfers one copy of the output to the standard output, and the other copy to the corresponding file)
Print the beginning and end of the table:
Awk 'in in {print "name age \ n --------------"} {print $0} end {print "end-of"} 'awktest
Awk considerations:
1. Make sure that the entire awk command is enclosed in single quotes.
2. Make sure that all quotation marks in the command appear in pairs.
3. Make sure that the Action Statement is enclosed in curly brackets and the Condition Statement is enclosed in parentheses.
2. pipeline usage: |
For example, WHO | awk '{print $2 "\ t" $1 }'. It is used in combination with awk.
3. A small one written in ShellProgramDelete a temporary file and save the file name
#! /Bin/sh echo "This Is A removing temp files shell! "Echo-e" input path \ c "read path ls" $ path "/*~ | Tee-A rmpath.txt RM "$ path "/*~ Echo "RM OK! "
4. Rewrite operator, defining the Terminator: Command <delimiter: CAT> leeboytext.txt <leeboy. When "leeboy" is input, the content above is forwarded to the leeboytext.txt file.
5. error message record: awk '{print $1 "}' leeboytext.txt> leeboy.txt 2> & 1. Merge the standard output and standard error output to the leeboy.txt file. (It can be understood that the content of 2 is redirected to 1)
6. awk 'in in {print "----- name ---"} {print $0} end {print "-- end --"} '<End:AwkThe statement does not specify a specific file. You need to manually enter the file.EndSubmit all data and runAwkCommand output data.
7. Use of the file descriptor and exec (to execute an operation:
#! /Bin/sh # redirects the file to the standard input, and specifies file descriptor 4 as the standard input (which can be understood as redirecting the file content to the standard input, in the redirected file descriptor) exec 4 <& 0 0 <.. /leeboy.txt read line1 # Read a row of read line2 exec 0 <& 4 # disable file descriptor 4 echo $ line1 echo $ line2