首页 > 系统服务 > 详细

shell脚本中head命令的使用

时间:2015-12-07 22:26:48      阅读:409      评论:0      收藏:0      [点我收藏+]

shell脚本中head命令的使用

在写shell脚本时,例如for循环中使用到了head命令

错误的使用方式是:

 

for i in $maptask;(此处少了;可加可不加)

do

#cat typescript | grep "number of splits:"* | awk -F ‘ ‘ ‘{print $7}‘ | awk -F ‘:‘ ‘{print "\t" $2}‘ >> m.txt
#cat typescript | grep "Transferred 0 bytes in "* | awk -F ‘ ‘ ‘{print "\n" $9}‘ >> m.txt
maptask=`cat typescript | grep "number of splits:"* | head -$i | tail -1 | awk -F ‘ ‘ ‘{print $7}‘ | awk -F ‘:‘ ‘{print $2}‘`
reporttime=`cat typescript | grep "Transferred 0 bytes in "* | head -$i | tail -1 | awk -F ‘ ‘ ‘{print $9}‘`
`echo -e "$maptask\t$reporttime" >> m.txt`
#cat typescript | grep "number of splits:"* | head -$i | tail -1 | awk -F ‘ ‘ ‘{print $7}‘ | awk -F ‘:‘ ‘{print "\t" $2}‘ >> m.txt
#cat typescript | grep "Transferred 0 bytes in "* | head -$i | tail -1 | awk -F ‘ ‘ ‘{print $9}‘ >> m.txt
done

或者

for((i=0;i<=num;i++));(同上)
do
#cat typescript | grep "number of splits:"* | awk -F ‘ ‘ ‘{print $7}‘ | awk -F ‘:‘ ‘{print "\t" $2}‘ >> m.txt
#cat typescript | grep "Transferred 0 bytes in "* | awk -F ‘ ‘ ‘{print "\n" $9}‘ >> m.txt
maptask=`cat typescript | grep "number of splits:"* | head -$i | tail -1 | awk -F ‘ ‘ ‘{print $7}‘ | awk -F ‘:‘ ‘{print $2}‘`
reporttime=`cat typescript | grep "Transferred 0 bytes in "* | head -$i | tail -1 | awk -F ‘ ‘ ‘{print $9}‘`
`echo -e "$maptask\t$reporttime" >> m.txt`
#cat typescript | grep "number of splits:"* | head -$i | tail -1 | awk -F ‘ ‘ ‘{print $7}‘ | awk -F ‘:‘ ‘{print "\t" $2}‘ >> m.txt
#cat typescript | grep "Transferred 0 bytes in "* | head -$i | tail -1 | awk -F ‘ ‘ ‘{print $9}‘ >> m.txt
done

 

shell脚本中head命令的使用

原文:http://www.cnblogs.com/xiaomila-study/p/5027322.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!