I’m trying to write an awk script which checks certain conditions and throws away lines meeting those conditions.
The specific condition are to throw away the first two lines of the file and any line that starts with the text xyzzy:. To that end, I coded up:
awk '
NR < 2 {}
/^xyzzy:/ {}
{print}'
thinking that it would throw away the lines where either of those two conditions were met and print otherwise.
Unfortunately, it appears that the print is being processed even when the line matches one of the other two patterns.
Is there a C-like continue action that will move on the next line ignoring all other condition checks for the current line?
I suppose I could use something like ((NR > 1) && (!/^xyzzy:/)) {print} as the third rule but that seems rather ugly to me.
Alternatively, is there another way to do this?
Use the keyword
nextas your actionThis keyword is often useful when you want to iterate over 2 files; sometimes it’s the same file that you want to process twice.
You’ll see the following idiom: