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.
One technique is to use an unusual character or string to separate records. For example, you could use the formfeed character (written ' \f ' in awk , as in C) to separate them, making each record a page of the file. To do this, just set the variable RS to "\f" (a string containing the formfeed character).
To comment out multiple code lines right-click and select Source > Add Block Comment. ( CTRL+SHIFT+/ )
In the awk language, a comment starts with the number sign character (' # ') and continues to the end of the line. The ' # ' does not have to be the first character on the line. The awk language ignores the rest of a line following a number sign.
For example: awk -F, ' program ' input-files. sets FS to the ' , ' character. Notice that the option uses an uppercase ' F ' instead of a lowercase ' f '. The latter option ( -f ) specifies a file containing an awk program.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With