Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

grep every even line 3

Status
Not open for further replies.

tini1208

Technical User
Feb 13, 2006
56
DE
hi all,

i don't know, if it is possible, but i want to extract every even line from a big file.

the file looks like this:

lon lat height
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 6 6
7 7 7

now, i want to extract line 2, 4, 6 etc.

is this possible? do i need linenumbers?

cheers
 
[tt]awk '!NR%2' /path/to/your/big/file[/tt]

or

[tt]awk 'NR%2'[/tt]

depending on if you're count from line 0 or line 1...


HTH,

p5wizard
 
p5wizard,
That is so beautiful and simple. It's the e=mc2 of awk. I had a solution also based on the modulo, but nothing so classy. As Antione de St Exupery said, you know you've achieved perfection, not when there's nothing more to add, but when there's nothing more to take away
 
hi p5wizard

thank a lot for our answer.
the command awk '!NR%2' infile does not work, error: NR: Event not found

but the second command works very well!!!! thank a lot!

 
awk '!(NR%2)'

then?

It looks like bash history processing is getting in the way...

HTH,

p5wizard
 
yes!!! awk '!(NR%2)' works very well!
thank you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top