Sed与Gawk编辑器使用指南
1. gawk程序的使用
gawk编辑器允许将程序存储在文件中,并在命令行中引用。以下是一个示例:
$ cat script2.gawk
{print $1 "'s home directory is " $6}
$
$ gawk -F: -f script2.gawk /etc/passwd
root's home directory is /root
daemon's home directory is /usr/sbin
bin's home directory is /bin
[...]
christine's home directory is /home/christine
sshd's home directory is /run/sshd
$
这个 script2.gawk 程序脚本使用 print 命令打印 /etc/passwd 文件中的用户名(字段变量 $1 )和用户主目录(字段变量 $6 )。
在程序文件中可以指定多个命令,只需将每个命令放在单独的一行,不需要使用分号。例如:
$ cat script3.gawk
{
text = "'s home directory is "
print $1 text $6
}
$
$ gawk -F: -f script3.gawk /etc/passwd
root'
Sed与Gawk文本处理教程
超级会员免费看
订阅专栏 解锁全文
76

被折叠的 条评论
为什么被折叠?



