-1
echo "Enter line number to display"
read number
sed -n $number /etc/passwd

I need to display only one line of text given by the user, in possible easy way. Above line is giving me error: sed -e expression char3,extra characters after command.

What am I doing wrong? Thanks

Rikardo
  • 79
  • 1
  • 10
  • 3
    Possible duplicate of [view a particular line of a file denoted by a number](http://stackoverflow.com/questions/5418908/view-a-particular-line-of-a-file-denoted-by-a-number), or [bash tool to get nth line from a file](http://stackoverflow.com/questions/6022384/bash-tool-to-get-nth-line-from-a-file). – Benjamin W. Oct 19 '16 at 18:28

1 Answers1

1

the correct command is:

sed -n ${number}p /etc/passwd

(p is command to print)

Of course sed will do nothing useful after that, so it's even better to quit after having printed like Benjamin hinted to avoid reading the rest of the file:

sed -n ${number}'{p;q}' /etc/passwd
Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219