Computer Science, asked by sanjanaaveesam9184, 1 year ago

Write a shell script that accepts a file name, starting and ending line numbers as arguments and displays all the lines between the given line numbers

Answers

Answered by paulaiskander2
0

The script is:

`

eval "sed -n '$2,3$p' $1"

`

The script uses the tool sed which is used to output the contents to the console. Sed is passed a the -n flag to choose which lines are output to the console. The format is sed -n '<start>,<end>p' <filename>. The arguments are passed in the order seen above where the filename is passed first, then the start line number then the end file number. After the string is parsed, we call eval on it to run the string as a bash command.

Answered by aqibkincsem
5

echo "enter the filename", read fname, echo "enter the starting line number", read s, echo "enter the ending line number", read n, sed -n $s,$n\p $fname | cat > newline, cat newline.


The number of arguments is represented by file name starting and ending the line numbers are displayed all the lines.

Similar questions