shell腳本中head命令的使用typescript
在寫shell腳本時,例如for循環中使用到了head命令shell
錯誤的使用方式是:spa
for i in $maptask;(此處少了;可加可不加)ip
doit
#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
donefor循環
或者awk
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循環