cluelessandsad
cluelessandsad

Reputation: 33

AWK script ignore first line

I am iterating through a csv file with awk using the command gawk -f script.awk example.csv.

script.awk is a file containing my commands:

BEGIN{FS=","}
pattern {command}
pattern {command}
END{print output}

If I wanted to skip the first line of the csv file, where would I put the NR>1 command in script.awk?

Upvotes: 3

Views: 2768

Answers (1)

Cyrus
Cyrus

Reputation: 88646

I suggest:

BEGIN{FS=","}
NR==1 {next}
pattern {command}
pattern {command}
END{print output}

From man awk:

next: Stop processing the current input record. Read the next input record and start processing over with the first pattern in the AWK program. Upon reaching the end of the input data, execute any END rule(s).

Upvotes: 8

Related Questions