Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 09-19-2005, 10:09 AM   #1
Mr. Gone
LQ Newbie
Registered: Mar 2004
Posts: 29

Rep: Reputation: 15
Remove odd lines from a text file

I'd like to find a way to remove odd lines from a text file. I've found examples of removing lines, but in those cases they were the first or last three lines, or else lines that contained a certain word, and I haven't been able to adapt them to my needs (not to surprise, being a newbie).

I suppose it could probably be done with sed, but my knowledge about it is zero.

I'm open to any suggestion: a pipe, a bash/perl script, sed/awk...

I know this will probably be a lame question for most of you, so I appeal to your indulgence.

Many thanks in advance.
Old 09-19-2005, 10:15 AM   #2
Registered: Jan 2005
Distribution: Slackware current (and others)
Posts: 188

Rep: Reputation: 30
tHIS will probably do what U want:

sed -n '~2p'


sed -n '1~2p'
Old 09-19-2005, 11:16 AM   #3
Mr. Gone
LQ Newbie
Registered: Mar 2004
Posts: 29

Original Poster
Rep: Reputation: 15
Thank you very much.

The first option (sed -n '~2p') gave me an error:

"sed: -e expression #1, char 2: Cannot use +N or ~N as first address"

But the second option worked perfectly. It removed even lines, but using '2~2p' instead of '1~2p' it removed odd lines.

Thanks again.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Grab text lines in text file LULUSNATCH Programming 1 12-02-2005 10:55 AM
How to remove lines from a file doza Linux - General 2 04-27-2005 11:59 AM
remove identical lines in a file benjithegreat98 Linux - General 4 04-24-2004 06:12 AM
How do i remove blank lines from a file? kakho Programming 1 04-15-2004 03:57 AM
[bash] remove lines from a file Drimo Programming 3 03-20-2004 11:16 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:27 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration