shell 处理文件脚本

[root@centos-6 ~]# cat info_file.txt
lys:28:shanxi
zhy:28:shanxi
[root@centos-6 ~]# cat info_file2.txt
lys 28 shanxi
zhy 28 shanxi
[root@centos-6 ~]# cat print.sh
#!/bin/bash
for i in `cat info_file.txt` do name=$(echo $i |awk -F : '{print $1}')
age=$(echo $i |awk -F : '{print $2}')
address=$(echo $i |awk -F : '{print $3}') echo "$name | $age | $address "
done
[root@centos-6 ~]# cat while.sh
#!/bin/bash while read a b c do echo $a $b $c done <info_file2.txt
[root@centos-6 ~]# sh print.sh
lys | 28 | shanxi
zhy | 28 | shanxi
[root@centos-6 ~]# sh while.sh
lys 28 shanxi
zhy 28 shanxi
[root@centos-6 ~]#
[root@centos-6 ~]# cat shift.sh
#!/bin/bash echo "print $1" [ "$1" = "lys" ] && shift echo "print $1" ping -c 2 $1
[root@centos-6 ~]# sh shift.sh lys www.baidu.com
print lys
print www.baidu.com
PING www.a.shifen.com (14.215.177.37) 56(84) bytes of data.
64 bytes from 14.215.177.37: icmp_seq=1 ttl=128 time=147 ms
64 bytes from 14.215.177.37: icmp_seq=2 ttl=128 time=144 ms --- www.a.shifen.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 5315ms
rtt min/avg/max/mdev = 144.476/146.061/147.646/1.585 ms
[root@centos-6 ~]# ^C
[root@centos-6 ~]# sh shift.sh zht www.baidu.com
print zht
print zht
ping: unknown host zht
[root@centos-6 ~]#
上一篇:小言C指针


下一篇:phonegap退出android程序