Linux awk 命令(Linux awk 命令语法与运算符)
awk
命令概述 :
awk
可用于处理文本文件 (pattern scanning and processing language)
$ awk --help
Usage: awk [POSIX or GNU style options] -f progfile [--] file ...
Usage: awk [POSIX or GNU style options] [--] 'program' file ...
POSIX options: GNU long options: (standard)
-f progfile --file=progfile
-F fs --field-separator=fs
-v var=val --assign=var=val
Short options: GNU long options: (extensions)
-b --characters-as-bytes
-c --traditional
-C --copyright
-d[file] --dump-variables[=file]
-e 'program-text' --source='program-text'
-E file --exec=file
-g --gen-pot
-h --help
-L [fatal] --lint[=fatal]
-n --non-decimal-data
-N --use-lc-numeric
-O --optimize
-p[file] --profile[=file]
-P --posix
-r --re-interval
-S --sandbox
-t --lint-old
-V --version
gawk is a pattern scanning and processing language.
By default it reads standard input and writes standard output.
Examples:
gawk '{ sum += $1 }; END { print sum }' file
gawk -F: '{ print $1 }' /etc/passwd
实例 :
################################################
#每行按空格或 tab 键分隔,输出第1,4项
(base) [biocodee@localhost ~]$ head log.txt
2 this is a test
3 Are you like awk
This's a test
10 There are orange,apple,mongo
(base) [biocodee@localhost ~]$ awk '{