how to ignore blank lines and comment lines using awk

后端 未结 3 1058
清酒与你
清酒与你 2021-01-01 03:59

i am writing this code:

awk -F\'=\' \'!/^$/{arr[$1]=$2}END{for (x in arr) {print x\"=\"arr[x]}}\' 1.txt 2.txt

this code ignore blank lines,

相关标签:
3条回答
  • 2021-01-01 04:21
    awk 'NF && !/^[:space:]*#/' data.txt
    

    Because '[:space:]*' catches none or more spaces.

    0 讨论(0)
  • 2021-01-01 04:29
    awk 'NF && $1!~/^#/' data.txt
    

    Will print all non-blank lines (number of fields NF is not zero) and lines that don't contain # as the first field.

    It will handle a line of whitespace correctly since NF will be zero, and leading blanks since $1 will ignore them.

    0 讨论(0)
  • 2021-01-01 04:36

    Change !/^$/ to

    !/^($|#)/
    

    or

    !/^($|[:space:]*#)/
    

    if you want to disregard whitespace before the #.

    0 讨论(0)
提交回复
热议问题