- 7
- 0
- 约1.54万字
- 约 34页
- 2017-06-05 发布于河南
- 举报
AWK讲解步骤(国外英文资料)
AWK讲解步骤
awk
grammar
Awk [options] commands files
The option
The -f defines the field delimiter, and the default delimiter is a contiguous space or TAB
Use the -f parameter in option to define the interval symbol
In the order of $1, $2, and $3, you represent each row in the files in different fields separated by an interval sign
The NF variable represents the number of fields in the current record
The -v defines variables and assigns values that can be borrowed from shell variables in the same way
The command
Processing before reading processing
Process BEGIN {awk_cmd1 before reading. Awk_cmd2}
Line processing: addressing commands
Addressing methods: regular, variable, comparison and relational operations
The regular needs to be enclosed
^ the beginning of a line
$end-of-line
Any single character except a newline character
* zero or more of the leading characters
* all characters
Any character in the [] character group
(^) within the character groups on each character invert (mismatches within each character)
^ (^) is not the character at the beginning of line inside character groups
[a-z] lower case letters
[a-z] capital letters
[a-z] lower case and capital letters
[0-9]
\ the word head word is usually separated by space or special characters, and successive strings are used as words
\
Extend the regular gar-r parameter or escape
Sed - n / roo \? / p / etc/passwd
Sed - rn / roo? / p / etc/passwd
? The leading character zero or one
+ one or more leading characters
ABC | def or ABC def
A (BC | DE) f abcf or adef
X \ {m \} x appears m times
X \ {m, \} x appears m times to many times (at least m times)
X \ {m, n \} x appears m times to n times
NR variable addressing
NR is the number of lines that AWK reads
The FNR indicates the number of rows in the file that is read in the row
# awk {print NR, FNR, $1} file1 file2
1 1 aaaaa
2 2 BBBBB
3 3 CCCCC
4 1 DDDDDD
5 2 eeeeee
6 3 FFFFFF
#
The logical operation can be directly referenced by the domain
= = = =. ~! ~
# awk NR
原创力文档

文档评论(0)