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!

print every Nth line from a file 1

Status
Not open for further replies.

Josewr

Technical User
Feb 28, 2005
15
US
I have a file with about 200,000 lines. They are 0.01 sec apart. I want to pick every Nth line and copy to a separate file. The time appears on column 18th. I named the AWK file "Decimate".
I have tried:

BEGIN { time = 61400}
{{ if ( $18 > time )

print $0 >> "Output_file.asc"}

time = time + 5; }

# Command line: gawk -f Decimate Input_file.asc

¿What am I doing wrong? Thanks!
I think is incrementing time before it gets to the next line.
 
You're right, it is incrementing time before it gets to the next line, because the outside set of { ... } braces are executed for every input line.

You should only increment the time when you match a line. Try this:

Code:
        [green]BEGIN[/green] { time = 61400 }
        [blue]$18[/blue] > time {
                [b]print[/b] [blue]$0[/blue] >> [red]"[/red][purple]Output_file.asc[/purple][red]"[/red]
                time = time + 5;
        }

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top