Http://www.chinaunix.net/old_jh/24/691456.htmlhttp://wenku.baidu.com/view/ebac4fc658f5f61fb736664d.html awk usage: awk 'pattern {action }'
Variable name meaning
Number of argc command line Variables
Argv command line meta Array
Filename current input file name
Number of records in the current FNR File
The input field delimiter of FS. The default Delimiter is a space.
RS input record delimiter
Number of dom
[Copyright statement: reprinted. Please retain the Source: blog.csdn.net/gentleliu. Mail: shallnew at 163 dot com]
Awk has many built-in variables used to set environment information. These variables can be changed. The following are the built-in variables of awk:
Number of argc command line parameters
Argv command line parameter arrangement
Environ supports the use of system environment variables in the q
Actual Application of awk: Text Merge
Use the awk command to combine the two lines with the same names in the following two files[Root @ localhost ~] # Cat 1.txtHan Hailin, 21 years oldHai linhan, 23 years oldHan Linhai, 22 years oldLin haihan, 24 years old[Root @ localhost ~] # Cat 2.txtHan Linhai maleHai Lin Han NanHan Hailin maleLin haihan Nan
Output result:Han Hailin, 21, male[Root @ localhost ~] #
end.Domains and recordsDomain ID: $1, $2 ,..., $ N. Use commas to separate fields. $0 indicates all domains.Print domain or all domain: Print commandNote: When an awk error occurs, you can find it:1. Make sure that the entire awk command is enclosed in single quotes2. Make sure all quotation marks in the command are enclosed in pairs.3. Make sure that the Action Statement is enclosed in curly brackets and
changed, and some of the most commonly used variables are given below.ARGC command-line arguments argv command-line parameter arrangement environ support the use of system environment variables in queues filename awk browses the file name Fnr the number of records to browse files FS Set input field delimiter, equivalent to command line-F option NF Browse r
is space. Regular Expressions are supported. For example, the [] character group is used as the separator below.
NF: number of fields currently processed. $0 indicates the entire record. $1 indicates the first field and $ NF indicates the last field.
[[emailprotected]awk]#catboracle:x:500:500::/home/oracle:/bin/bash[[emailprotected]awk]#awk‘BEGIN{FS="[:/]"}{for(i=1;i
corresponding shell'/root/{print $7}'/etc/passwd /bin/bash Action{print $7} is specified here.awk built-in variablesAwk has many built-in variables for setting up environment information, which can be changed, and some of the most commonly used variables are given below.ARGC command-line arguments argv command-line parameter arrangement environ support the use of system environment variables in queues filename
,AnandRam,Developer105,JaneMiller,SalesManager
Print command: The position parameter $1 $2... $ n represents the 1st columns and 2nd columns of a record, respectively. column N
#awk-F,‘{print$1,$2}‘employee.txt101JohnnyDoe102JasonSmith103RajReddy104AnandRam105JaneMiller
Built-in variables of awk:
FS: input field separator
OFS: output field separator
RS: Input record separator input record Separator
ORS: O
command-line arguments argv command-line parameter arrangement environ support the use of system environment variables in queues filename awk browses the file name Fnr the number of records to browse files FS Set input field delimiter, equivalent to command line-F option NF Browse record number of fields nr
that have the root keyword/etc/passwd and display the corresponding shellawk ' /root/{print $7} ' /etc/passwd /bin/bashAction{print $7} is specified here.awk built-in variablesAwk has many built-in variables for setting up environment information, which can be changed, and some of the most commonly used variables are given below.ARGC command-line arguments argv command-line parameter arrangement environ support the use of system environment var
commonly used variables are given below.ARGC command-line arguments argv command-line parameter arrangement environ support the use of system environment variables in queues filename awk browses the file name Fnr the number of records to browse files FS Set input field delimiter, equivalent to command line-F option NF Browse record number of fields
command-line arguments argv command-line parameter arrangement environ support the use of system environment variables in queues filename awk browses the file name Fnr the number of records to browse files FS Set input field delimiter, equivalent to command line-F option NF Browse record number of fields nr
/passwdSearch all lines that have the root keyword/etc/passwd and display the corresponding shellawk ' /root/{print $7} ' /etc/passwd /bin/bashAction{print $7} is specified here.awk built-in variablesAwk has many built-in variables for setting up environment information, which can be changed, and some of the most commonly used variables are given below.ARGC command-line arguments argv command-line parameter arrangement environ support the use of
command-line arguments argv command-line parameter arrangement environ support the use of system environment variables in queues filename awk browses the file name Fnr the number of records to browse files FS Set input field delimiter, equivalent to command line-F option NF Browse record number of fields nr
/passwd and display the corresponding shell# awk-f: '/root/{print $7} '/etc/passwd /bin/bashAction{print $7} is specified here.awk built-in variablesAwk has many built-in variables for setting up environment information, which can be changed, and some of the most commonly used variables are given below.ARGC command-line arguments argv command-line parameter arrangement environ support the use of syste
command-line arguments argv command-line parameter arrangement environ support the use of system environment variables in queues filename awk browses the file name Fnr the number of records to browse files FS Set input field delimiter, equivalent to command line-F option NF Browse record number of fields nr
} 'fawk. a1 xiao 25 beijing 90002.3 display the rows of xiao or $2 including liu, such as $2[Root @ store_2 awk] # awk '{if ($2 = "xiao") | ($2 ~ /Liu/) print $0} 'fawk.1 xiao 25 beijing 90002 liuwenjing 24 beijing 50002.3 calculate how many rows of NR are displayed[Root @ store_2 awk] #
Invoking awk in a shell script is very natural and simple, so let's look at awk calling the shell and passing the variable to the Shell,awk using the variables in the shell, awk passing the value to the shell variable
Invoking awk in a shell script is very natural and sim
of the most commonly used variables are given below.ARGC command-line arguments argv command-line parameter arrangement environ support the use of system environment variables in queues filename awk browses the file name Fnr the number of records to browse files FS Set input field delimiter, equivalent to command line-F option NF Browse record number of fi
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.