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
all lines that have the root keyword/etc/passwd and display the 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 environmen
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# Awk '{print NR}' grade.txt12345#
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 number of command line argumentsARGV Command line parameter arrangementENVIRON support for the use of system environment variables in queuesFileName awk browses the file nameFNR number of records to browse filesFS sets the input domain delimiter, which is e
All users who are familiar with linux know that linuxshell is very powerful in text processing. all users who are familiar with linux 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 texts, sed is used for text editing and replacement, and awk is also the most powerful. it is often used
of the contents of each row). Search support for the regular, for example, root start: awk-f: '/^root/'/etc/passwd#awk-F: '/root/'/etc/passwdroot:x:0:0:root:/root:/bin/bash5. Search for all lines that have the root keyword/etc/passwd and display the corresponding shell. Action{print $7} is specified here.# awk-f: '/root/{print $7} '/etc/passwd /bin/b
(1) awk principleThe principle of awk is to process the data in a file line by row, find content that matches what is given on the command line, and then program the next step if a match is found. If no match is found, continue with the next line.(2) Awk combatSed-n '/jd.com/p ' jfedu.txt awk '/jd.com/' jfedu.txtCommen
: '/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 number of command line argumentsARGV Command line parameter arrangementENVIRON support for the use of system environment variables in queuesFileName awk browses the file nameFNR number of records t
AWK resolution, awk resolutionCut command limitations
Df-h | cut-d ""-f 5/etc/passwd
The cut command cannot correctly intercept the content with spaces as the separator.
AWK format
Awk 'condition 1 {Action 1} condition 2 {Action 2 }... 'Filename'
Condition (Pattern) [relational expressions are generally used as cond
Awk string truncation, awk string1) how to split the current string with $0, for example:Cat num.2012032911 | awk '{print $2}' | awk '{split ($0, B, "."); print B [2]}' | cut-c 3-Obtain the second column. For example, if the second column is com. sb3456.you, you can obtain sb3456 from the current split string, and the
awk browsesFNR#number of records to browse filesFs#set input field delimiter, equivalent to command line-F optionNf#number of fields to browse for recordsNr#the number of records that have been readOFS#output Field delimiterORS#Output Record delimiterRs#Control record delimiterIn addition, the $ variable refers to the entire record. $ $ represents the first field of the current row, which is the second field of the current row,...... And so onStatist
of spaceawk ' {printf ' the name is%-15s ID is%8d\n ", $1,$3} ' employeesThe name is Tom ID is 4424The name is Mary ID is 5346The name is Sally ID is 1654The name is Billy ID is 16833. Records and Domains in awk:The default record delimiter in awk is carriage return, which is stored in the built-in variables ors and Rs. The-$ variable refers to the entire record.#这等同于print的默认行为. awk ' {print $} ' employees
24 beijing 50003 weijianjun 29 shanghai 80004 wanmingyang 28 beijing 50005 tianzhiyu 25 beijing 55006 zhouhaoxing 23 beijing 50002.1 shows the full line of xiao, such as $2, or $2, which is equal to liu.[Root @ store_2 awk] # awk '{if ($2 = "xiao") | ($2 = "liu") print $0} 'fawk. a1 xiao 25 beijing 90002.3 display the rows of xiao or $2 including liu, such as $2[Root @ store_2
/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 awk browses the file name Fnr the
delimiterNumber of domains in the current NF recordNo. Of NR records so farOFS output domain separatorORS output record separator1. awk '/101/'file: The file contains 101 matching rows.Awk '/101/,/105/' fileAwk '$1 = 5' fileAwk '$1 = "CT"' file must contain double quotation marksAwk '$1 * $2> 100' fileAwk '$2> 5 $2 2.
The problem of passing parameters in awk has always been a headache for many people. The following is a summary:
I. Direct call of awk scripts .
For example, the following script requires the calculation of the total number of logs on the 15th to 30th. $3 indicates the domain that distinguishes the encoding of different pages. The script is as follows:
#/Bin/sh;Page = $1;I = 15;While test $ I-le 30Do#
per IP is sorted from small to large:
awk ' {++s[$1]} END {for (a in S) print S[a],a} ' log_file | Sort-n
See which pages are accessed by an IP (for example, 202.106.19.100):
grep ^202.106.19.100 Access.log | awk ' {print $1,$7} '
Statistics August 31, 2012 14 o'clock how much IP access is in:
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.