Rikardo Rikardo - 1 year ago 68
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?

Answer Source

the correct command is:

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

(p is command to print)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download