Interviews Questions, Algorithms, Aptitude, C Interview Program, C Theory Question, Aptitude Tricks, Test Series,

Sunday 28 April 2019

IOPP Program No.3. B

Program No.3. B 

Write a shell script to display the lines of a given file. The line numbers are specified as a range. For example, if the range specified is 10-25, then the lines from 10 to 25 of the file are to be displayed. 

Solution:

echo "Enter the filename."
read filename
echo "Enter the starting line."
read x
echo "Enter the ending line."
read y
if [ $x -gt $y ]
then
echo "ERROR: Ending Line Should Greater Starting Line"
exit
fi
sed -n $x,$y\p $filename > cat > newline
cat newline

0 comments:

Post a Comment