Friday, 30 March 2018

Shell script to display file contents from middle

#Display file contents between a range
echo "Enter file name"
read fname
echo "Enter start and end line"
read m n

if [ -f $fname ]
then
      tail -n +$m $fname>tfile
      range=`expr $n - $m`
      echo $range
      head -$range tfile

else
      echo "'$fname' does not exist"
fi



OUTPUT
csc@csc-SVE1513CYNB ~ $ sh dispmid.sh
Enter file name
file2
Enter start and end line
2 5
3
102 Babu CEO
103 Banu CIO
101 Anu MD

No comments:

Post a Comment