一.Shell命令,查看系统用户第1列信息
cat /etc/passwd |awk -F: '{print $1}'
二.Awk脚本
1.编辑test.awk脚本
vi test.awk
BEGIN{
FS=":"
}
{
print $1
}
2.执行test.awk
awk -f test.awk /etc/passwd
三.Shell脚本
1.编辑test.sh脚本
vi test.sh
#!/bin/bash
awk '
BEGIN{
FS=":"
}
{
print $1
}
' $*
3.设置权限
chmod +x test.sh
#或
chmod 0700 test.sh
4.执行test.sh脚本
./test.sh /etc/passwd
四.shell脚本编写第二种方法
1.编写shell脚本
vi test.sh
#!/bin/bash
awk '
BEGIN{
FS=":"
}
{
print $1
}
' /etc/passwd
2.执行shell脚本
./test.sh