shell脚本中head命令的使用

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

 

posted on 2015-12-07 20:17  小米辣  阅读(3764)  评论(0编辑  收藏  举报

导航