shell脚本 逐行读取文本并且 进行字符串的截取

 

例如有个文本文件

1234  ji

adfa jiji

adfasd qqwe

    // 注意一定要有个回车,这样脚本才会读到最后一行 

 

while read typeline
do 
#get line txt
typeInf=$typeline
#get type
#去除右边第一个空格开始的后边所有字符
typetmp=${typeInf%% *}
#judge type same
if [ "$typetmp" = "$type" ]
then
echo sametype:$typetmp
#get count
pcount=${typeInf:0-1}
fi
done < $file

  

 

posted @ 2016-03-22 13:31  ishizhen  阅读(4026)  评论(0编辑  收藏  举报