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
原文:http://www.cnblogs.com/xiaomila-study/p/5027322.html