AWK Delimiter
Since awk field separator seems to be a rather popular search term on this blog, I’d like to expand on the topic of using awk delimiters (field separators).
Two ways of separating fields in awk
There’s actually more than one way of separating awk fields: the commonly used -F option (specified as a parameter of the awk command) and the field separator variable FS (specified inside the awk script code).
awk -F field separator
As you may have seen from the awk field separator post, the easiest and quicked way to use one is by specifying -F command like option for awk (in the example we’re extracting the last octet of the IPv4 address):
Field Separator (FS) variable in awk
As your awk scripting gets better and more complex, you’ll probably recognise that it’s best to put such options inside the awk script instead of passing them as command line options. The benefit is, of course, that you don’t risk getting different (wrong!) results just because you forgot to specify a command line option – everything is contained in your script, so you run it with minimal set of parameters and always get the same result.
So, the second way of separating fields in awk script is by using the FS (field separator) variable, like this:
See Also
Since awk field separator seems to be a rather popular search term on this blog, I’d like to expand on the topic of using awk delimiters (field separators).
Two ways of separating fields in awk
There’s actually more than one way of separating awk fields: the commonly used -F option (specified as a parameter of the awk command) and the field separator variable FS (specified inside the awk script code).
awk -F field separator
As you may have seen from the awk field separator post, the easiest and quicked way to use one is by specifying -F command like option for awk (in the example we’re extracting the last octet of the IPv4 address):
Field Separator (FS) variable in awk
As your awk scripting gets better and more complex, you’ll probably recognise that it’s best to put such options inside the awk script instead of passing them as command line options. The benefit is, of course, that you don’t risk getting different (wrong!) results just because you forgot to specify a command line option – everything is contained in your script, so you run it with minimal set of parameters and always get the same result.
So, the second way of separating fields in awk script is by using the FS (field separator) variable, like this: