awk seems to match all the patterns matching an expression and executes the corresponding actions. Is there a precedence that can be associated ?
For eg. In the below, lines starting with # (comments) are matched by both patterns, and both actions are executed. I want commented lines to match only the first action.
/^#.*/ {
// Action for lines starting with '#'
}
{
// Action for other lines
}
If you want to keep the code you already have mostly intact, you could just use the awk
next statement. Once you encounter the next
statement, awk
skips processing the current record and goes to the next line.
So if you put next
into the bottom your 1st block the 2nd block wouldn't be executed.
Why not simply if,else
:
awk '{ if ($0 ~ /^#/)
// Action for lines starting with '#'
else
// Action for other lines
}'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With