more on `sed`

1. Deleting 2-5 line from a file

sed ‘2,5d’ file.txt

2. Deleting from line 25 to end of a file

sed ‘2, \$d’ file.txt

3. Printing 5-8 line of a file

sed -ne 5,8p file.txt

4. Printing 6 to end

sed -ne “6, \$p” file.txt

5. Printing line 4, 7, 22

sed -ne 4p -e 7p -e 22p file.txt

6. Delete lines from a file matching a pattern –

sed -e ‘/pattern/d’ oldfile \> newfile

Advertisements

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


%d bloggers like this: