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 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 B
Support the use of system environment variables in the queue
Filename
Name of the file awk is browsing
FNR
Number of browsing file records
FS
Set the input domain separator, which is equivalent to the command line-F Option
NF
Number of browsing records
NR
Number of read records
OFS
Output domain Separator
ORS
Output reco
, 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 record nu
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
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
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 awk browses the file name Fnr the number of records to browse files FS Set input field delimiter, equivalent
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
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 awk browses the file name Fnr the number of records to browse files FS
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 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
segment, you can make a logical comparison between two segments.[Email protected] ~]# awk-f: ' $3> "5" $3In addition, you can also use and | | The meaning of "or". example, prints the 3rd paragraph greater than the 4th paragraph, and the 7th paragraph is the/bin/bash line;[Email protected] ~]# awk-f: ' $3>$4 $7== '/bin/bash ' passwd user1:x:600:501::/home/user1:/bin/bashexample, prints the 3rd paragr
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
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
in the behavior Processing unit, and the next line is processed automatically after the output of the current row until all rows have been processed.----------------------------------------------------------------------Options?-F "Symbol" specifies the split symbol for the column awk uses a space or \tab as the delimiter for the column by default----------------------------------------------------------------------Use of the
Awk processes multiple files
Awk processes multiple files one by one.
Demo1
$ cat $ cat 1.txt a 1 b 2c 3d 4$ cat 2.txt b 5 c 6d 7e 8$ awk ‘{print $0}‘ 1.txt 2.txta 1 b 2c 3d 4b 5 c 6d 7e 8
So how can we tell which file is being processed? Let's take a look at the built-in variables of awk.
Filename: Name of the file
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
Previous
We all know that Linux Shell is very powerful in text processing. There is a powerful set of text processing tools: grep, sed, awk. Grep is often used for searching and matching text and SEDCompositionThis edited replacement and awk are also the most powerful and often used for report generation! The processing efficiency is very high. A file of several hundred MB can also be completed in seconds!
you want to set it to #, write it to OFS = "#"Default delimiter of ORS output records is new line (\ n)The default RS control record delimiter is a new line (\ n)The following example shows the built-in variables of awk.NR allows you to quickly view the number of records. for example, you need to view the number of records after exporting database files.# Awk 'end {print NR} 'grade.txt5#
statement. The default Delimiter is space.
# Awk 'in in {FS = ":"; OFS = "="} {print $1, $3} '/etc/passwd
RS: input record seperator, which is the delimiter of the input record. The default value is new.
Example: Use a colon as the line break to output the full text
# Awk-v RS = ":" '{print $0}'/etc/passwd
ORS: Outpput Row Seperator, which is the line separator for output;
The default line Delimiter is g
, and then dividing the record by the specified field delimiter, populating the field, $ A represents all fields, representing the first field, $n representing the nth field , and then the action action corresponding to the execution mode is started. Then start reading the second record ... Until all the records have been read, the end operation is performed. Search all rows with the root keyword/etc/passwd#awk-F: '/root/'/etc/passwdroot:x:0:0:root:/r
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.