1.awk workflow
a) first execute BEGIN; b) read the file, read a record with /n newline splitting c) divide the record by the specified domain separator d) padding field, where $0 means all fields, $1 means the first field, $n means the first field (the default field separator is a blank key or a tab key) e) the action corresponding to the start execution mode action f) then starts Read the second record until all the records have been read g) Execute the END operation
2. Use the method
awk [-F field-separator] '{pattern + action}' {filenames} 1. Pattern represents what awk looks for in the data, and action represents a series of commands that are executed when a match is found. Action{} can have multiple statements separated by a ";". 2. [-F field separator] is optional. Filenames is the file to be processed. In awk, in each line of a file, each item separated by a domain separator is called a field. Typically, in the case of the unnamed -F domain separator, the default domain separator is a space.
3.awk built-in variable
ARGC command line parameter number ARGV command line parameter arrangement ENVIRON support queue system environment variable use FILENAME awk browse file name FNR browse file record number FS set input field separator, Equivalent to the command line -F option NF Browse the number of fields in the record NR Number of records read OFS Output field separator ORS Output record separator RS Control record separator
4.awk built-in string function
Gsub(r,s) replaces rgsub(r,s,t) with s throughout $0. Replaces rindex(s,t) with s throughout t. Returns the first position of string t in s length(s) returns s The length match(s,r) tests whether s contains the string matching the r (str,array,fs). On ss, divide s into sequences asprint(fmt,exp). Return the expsub(r,s) formatted by fmt. Replace shsubt(s,p) with the leftmost longest substring of $0. Return the suffix part of the string s from p to the substr(s,p,n). Return the suffix part of the string s starting from p and having a length of n.
5.BEGIN and END
BEGIN indicates that the operation END before processing any line indicates the processing performed after all the input lines have been processed.
6. Conditional statement
if (expression) { statement; statement; ... ...ifif (expression) { statement;} else { statement2;}if (expression) { statement1;} Else if (expression1) { statement2;} else { statement3;}7. Array
Because the subscript of an array in awk can be numbers and letters, the subscript of an array is often called a key. Both the value and the keyword are stored in a separate table for the key/value application hash. Since hashes are not stored sequentially, you will find that when displaying array contents, they are not displayed in the order you expect. Arrays, like variables, are created automatically when they are used. Awk also automatically determines whether it stores numbers or strings. In general, arrays in awk are used to collect information from records, which can be used to calculate sums, count words, and how many times the tracking template is matched.awk -F ':' 'BEGIN {count=0;} {name[count] = $1;count++;}; END{for (i = 0; i < NR; i++) print i, name[i ]}' /etc/passwdrootdaemonbinsyssyncgames......awk -F'\\t' '{ a[$1]++ }'END'{ for(j in a) print a[j],j }' filename | Sort -rn | The content of more filename is: apple banana apple apple banana pear output: 3 apple 2 banana 1 pear
Recently, some users have been reminding that when they open some built-in applications, the built-i
. Description Install VMware Workstation10 on Windows 7 system, install CentOS6.5 operating system
The problem of reboot and select prorer boot device of insert boot media in selectea boot device and
Recently, some users have reflected the error 15: file not found error after booting the reinstalled
Master files in the cleaning system have a trick
u disk initialization causes read instability how to solve?
Fast solution for graphics problems
.net service installation uninstall command line batcmd
Start the system service prompt "Error 3: The system can not find the specified path" How to solve?
How does the printer scan files to the computer?
The easiest way to delete the .svn folder under Windows
How to solve the rpc server is not available
Little-known hacker attack computer program
Boot prompt Error loading OS two solutions
How to deal with "unrecognized network prompts" in Win10 system?
VISTA weight loss accident removal driver solution
How to automatically disconnect the broadband connection when the Win7 network is idle
Reasons to upgrade to Windows 7 system
How to use Win8 system comes with screenshot gadgets
Win7 system can not be installed in the C drive solution
Win8 system settings file history drive
Win8, win8.1 use admin rights to run cmd method graphic tutorial
Using Group Policy to Improve Windows 7 System Security
Figure 2 shows two different ways to enter the safe mode experience