awk text field verification



  • We need to check whether the line field is text or number. I've been through this: if ($2 != /[0-9]/){...}else{...}but it's not a good design that works and only works the other block. I just met awk, so don't swear.



  • Use the operator. !~♪ Example:

    $ more ./tmp.txt
    1 aaaa
    2 2222
    3 c3c3
    $ awk '{ print $2 !~ /^[0-9]+$/; }' ./tmp.txt 
    1
    0
    1
    $
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2