jeudi 24 juin 2021

awk, skip current rule upon sanity check

How to skip current awk rule when its sanity check failed?

{
  if (not_applicable) skip;
  if (not_sanity_check2) skip;
  if (not_sanity_check3) skip;
  # the rest of the rules 
}

IMHO, it's much cleaner to write code this way than,

{
  if (!not_applicable) {
    if (!not_sanity_check2) {
      if (!not_sanity_check3) {
      # the rest of the rules
      }
    }
  }
}

1;

I need to skip the current rule because I have a catch all rule at the end.

UPDATE, the case I'm trying to solve.

There is multiple match point in a file that I want to match & alter, however, there's no other obvious sign for me to match what I want. hmmm..., let me simplify it this way, I want to match & alter the first match and skip the rest of the matches and print them as-is.

Aucun commentaire:

Enregistrer un commentaire