Computing.Net > Forums > Unix > Extracting range of lines from a fi

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Extracting range of lines from a fi

Reply to Message Icon

Name: pnbalaji
Date: February 13, 2008 at 14:36:23 Pacific
OS: AIX 4.3.3
CPU/Ram: 16GB
Product: IBM, 7026-H80
Comment:

Hi,

I have a file which contains 15 lines (could differ). I want to exclude the first 2 lines and the last 6 lines from this file. All the lines with in the range should be redirected into another file. Can some one help me?

I did this long back with an SED command, I am not able to find out that.

Thanks,
Balaji.


Thanks,
Balaji.



Sponsored Link
Ads by Google

Response Number 1
Name: James Boothe
Date: February 13, 2008 at 15:27:52 Pacific
Reply:

At the moment, I am struggling to get that done with only sed, but here is a tail|sed solution:

tail +3 myfile | sed -e :a -e '$d;N;2,6ba' -e 'P;D'


0

Response Number 2
Name: nails
Date: February 13, 2008 at 20:23:35 Pacific
Reply:

sed -e :a -e '$d;N;2,6ba' -e 'P;D' myfile.txt| sed '1,2d'


0

Response Number 3
Name: pnbalaji
Date: February 15, 2008 at 01:11:28 Pacific
Reply:

Thanks for the response. I used the tail, sed combo and it is working fine.

Thanks,
Balaji.


Thanks,
Balaji.


0

Response Number 4
Name: James Boothe
Date: February 15, 2008 at 14:10:12 Pacific
Reply:

OK, somewhat delayed, but for the record, here is a single sed command that will exclude the first 2 lines and the last 6 lines.

sed -e '1,2d' -e :a -e '$d;N;4,8ba' -e 'P;D' myfile


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Extracting range of lines from a fi

return no. of lines from grep www.computing.net/answers/unix/return-no-of-lines-from-grep/6508.html

Get the first line from a file www.computing.net/answers/unix/get-the-first-line-from-a-file/7981.html

Extracting lines from file using sh www.computing.net/answers/unix/extracting-lines-from-file-using-sh/7664.html