例如有個文本文件
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