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

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM