Sed/Awk Print Part Of File Based On Line Numbers

Here are the commands to print part of file based on their line numbers with sed/awk.

  • With sed

$ sed -n '4,10p' input.txt

Above command will prints from line 4 to 10.

  • With awk

$ awk 'NR==4,NR==10' input.txt

Above awk expression also prints form line 4 to 10.

-Sany

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s