Rikardo Rikardo - 1 month ago 7
Linux Question

CentOS - displaying 1 line of file only

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

Answer

the correct command is:

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

(p is command to print)