Alex Rivera | Logout

Multiline comment in awk

Asked 2012-07-20T07:59:00.983
13

I would like to know how to use multi line comment in awk. As of now I have been using # to comment a single line. Could someone guide me regarding this. Thank you.

awk
Edit
Report

1 Answer

20

There is no multiline comment in AWK, but you can fake it if you need to. Here is one technique 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 be able to have multiline comments for commenting out sections of code during debugging. I wouldn't necessarily use this technique for documentation since it may not be guaranteed that the non-code text would not be parsed for syntax errors.

It seems to also work in mawk.

answered 2012-07-20T11:33:37.373

Your Answer