You are not logged in.

#1 2009-02-28 00:44:17

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

[SOLVED] Using sed to pull two parts of a data file

I need to combine lines 1-20 and 41-60 of a file into a single stream.

I understand I can pull lines 1-20 with "sed -n 1,20p file.dat"

And I understand I can pull lines 41-60 with "sed -n 41,60p file.dat"

But how can I pull both sections with one command? Any ideas?

Last edited by tony5429 (2009-03-01 04:57:06)

Offline

#2 2009-02-28 01:03:04

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: [SOLVED] Using sed to pull two parts of a data file

sed -n '1,20p;41,60p' file.dat

also sed 21,40d unless 60 is not the last, then you'd need a ; construct too.

Offline

#3 2009-02-28 01:03:15

skottish
Forum Fellow
From: Here
Registered: 2006-06-16
Posts: 7,942

Re: [SOLVED] Using sed to pull two parts of a data file

You can use something like this. It prints lines 1-3 and 6-10 to test_file.

sed -n -e '1,3p' -e '6,10p' file.dat > test_file

Offline

#4 2009-02-28 01:54:28

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

Re: [SOLVED] Using sed to pull two parts of a data file

Sed is a simply amazing tool. Thanks for the help - it works fine now.

Offline

Board footer

Powered by FluxBB