shell逐行读取文件,并在每行开头部分添加行号,最后显示总行数
BASH:readbyrow.sh
#read file line by line
#!/bin/sh
if [ "$1" = "" ];then
exit 1
elif [ -f $1 ]; then
Count_Line=0
while read NAME GOODS NO PRICE
do
Count_Line=`expr $Count_Line + 1`
echo -e "$NAME/011$GOODS/011$NO/011$PRICE"
done<$1
else
echo "File $1 doesn't exit!"
exit 1
fi
echo -e "There are $Count_Line lines!"
保存运行