Awk multi-line comment

I would like to know how to use multi-line comment in awk. Right now I'm using # to comment out one line. Can anyone direct me to this. Thanks.

+6
source share
1 answer

There is no multi-line comment in AWK, but you can fake it if you need to. Here is one method that works, at least in GNU AWK ( gawk ):

 #!/usr/bin/awk -f 0 { You can use 0 to cause a block to not execute or be parsed } { print $2, $1, $3 if (0) { You can use if (0) in a similar manner inside a block } sum += $4 } 0 && /pattern/ { # prepend "0 &&" to other conditions to turn off a block print } 

It's nice to have multi-line comments for commenting sections of code during debugging. I would not necessarily use this method for documentation, since it cannot be guaranteed that text without code will not be parsed for syntax errors.

He also works at mawk .

+10
source

Source: https://habr.com/ru/post/920943/


All Articles