I have an example of a regular expression:
seq 20 | awk 'NR!~/^2$|^12$|^15$/'
The same, but with the chain expression:
seq 20 | awk 'NR != "2" && NR != "12" && NR != "15"'
Is it possible to write shorter string expression?
seq 20 | awk 'NR != "2" | "12" | "15" '
Thank you for the explanation.
Not to my knowledge. And like you have hinted at, you will need to use a regular expression if you would like to perform equality testing (or inequality testing, in this case) in this way.
If you have multiple values to ignore, consider using an array in the
BEGINblock. This will make the expression shorter (i.e. the expression is now simply:!(NR in array)) whenawkiterates through each line:Results:
If you there is some sort of pattern to the lines your trying to ignore, consider using a
forloop in theBEGINblock: