1.问题:在当前系统中打印出所有普通用户的用户和家目录(/etc/passwd)
2.显示当前系统中容量使用率大于5%的文件系统名称和挂载点
3.为/tmp/grub.conf文件中前三行的行首加#号
cp:拷贝
cd:切换
sed -r '1,3s#^#\##g' a.txt
awk 'NR>0&&NR<4{print "#"$0}' grub
4.通过notepad++打开,把一下内容输入到test.txt文件
姓名 区号 电话 三个月捐款数量
Mike Harrington:[510] 548-1278:250:100:175
Christian Dobbins:[408] 538-2358:155:90:201
Susan Dalsass:[206] 654-6279:250:60:50
Archie McNichol:[206] 548-1348:250:100:175
Jody Savage:[206] 548-1278:15:188:150
Guy Quigley:[916] 343-6410:250:100:175
Dan Savage:[406] 298-7744:450:300:275
Nancy McNeil:[206] 548-1278:250:80:75
John Goldenrod:[916] 348-4278:250:100:175
Chet Main:[510] 548-5258:50:95:135
Tom Savage:[408] 926-3456:250:168:200
Elizabeth Stachelin:[916] 440-1763:175:75:300
(1)显示所有电话号码
(2)显示Dan的电话号码
(3)显示Susan的名字和电话号码
(4)显示所有以D开头的姓
(5)显示所有区号为916的人名
awk -F "[ :]+" '$3~/\[916\]/{print $1}' test.txt
(6)显示Mike的捐款.显示每个值时都有以$开头.如$250$100$175
awk -F "[: ]+" '$1~/Mike/{print "$"$(NF-2),"$"$(NF-1),"$"$NF}' test.txt
awk -F ":" '$1~/Mike/{print "$"$3,"$"$4,"$"$5}' test.txt
awk -F'[ :]+' '/Mike/{print "¥"$(NF-2),"¥"$(NF-1),"¥"$NF}' test.txt
sed -rn 's#^M.*:(.*):(.*):(.*).*#$\1 $\2 $\3#gp' test.txt
(7)显示姓,其后跟一个逗号和名
awk -F "[: ]+" 'NR>1&&$1~/^[A-Z]/{print $1","$2}' test.txt
awk -F'[ :]+' 'NR>1&&!/^$/{print $2","$1}' test.txt
(8)在Jody开头的行前面添加oldboy
awk -F "[ :]+" '$1~/Jody/ {print "oldboy " $0}' test.txt
sed -ne '/Jody/p' -e 's#^#oldboy#g' test.txt
上一行添加oldboy
sed '/Jody/i oldboy' test.txt
awk -F "[ :]+" '$1~/Jody/ {print "oldboy\n" $0}' test.txt
(9)删除空白行