从文件中读取特定行的shell脚本

上一篇 / 下一篇  2008-04-11 21:47:44 / 个人分类:Shell

代码:

#!/bin/sh
#set -x
if [ "$#" -lt 1 ];then
echo "Usage $0 [file] "
exit 1
fi
echo "Enter the line you want to choose from:"
read FromLine
echo "Enter the line you want to choose to:"
read ToLine

rm -rf temp.txt
Line=`echo "$ToLine-$FromLine" | bc`

x=0
exec < $i # opens the file you want choose the line from
while read line # read from the file
do
if [ $x -lt $Line ];then
printf "%s\n" "$line" >>temp.txt
x=`expr $x + 1`
else
echo "DONE"
exit 1
fi
done

#set +x


TAG: Shell

 

评分:0

我来说两句

Open Toolbar