gawk linux,linux中gawk命令
終止gawk程序,使用Ctrl+D組合鍵產生一個EOF終止符。
[root@localhost ~]# gawk '{print "Hello World"}'
this is a test
Hello World
you need input ctrl+D to end the shell
Hello World
數據字段變量,默認分隔符是任意的空白字符(例如空格或制表符)
$0代表整個文本。
$1代表文本中的第1個數據字段
$2代表文本中的第2個數據字段
$n代表文本中的第n個數據字段
字段提取
[root@localhost shell]# cat helloworld.txt
one line of this file
two line of this file
three line of this file
four line of this file
five line of this file
[root@localhost shell]# gawk '{print $1}' helloworld.txt
one
two
three
four
five
-F分隔符
[root@localhost shell]# gawk -F: '{print $1}' /etc/passwd
root
bin
daemon
adm
lp
sync
shutdown
halt
operator
games
BEGIN打印之前執行腳本
[root@localhost shell]# cat helloworld.txt
Line 1
Line 2
Line 3
[root@localhost shell]# gawk 'BEGIN {print "The helloworld.txt File Contents:"};{print $0}' helloworld.txt
The helloworld.txt File Contents:
Line 1
Line 2
Line 3
在處理數據后運行腳本
[root@localhost shell]# gawk 'BEGIN {print "The helloworld.txt File Contents:"};{print $0}; END {print "The end."}' helloworld.txt
The helloworld.txt File Contents:
Line 1
Line 2
Line 3
The end.
總結
以上是生活随笔為你收集整理的gawk linux,linux中gawk命令的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ARP断网攻击(详细教程)
- 下一篇: linux 逗号分隔,linux-如何用