Low Orbit Flux Logo 2 D

AWK How To Change Field Separator

Changing the field separator in AWK is easy. This is one of the most common, basic things that you will want to be able to do with AWK.

You can change the field separator to a colon “:” using the “-F” parameter like this:

ps -ef | awk -F: '{print $1}'    

You can also use the “-v” parameter to set variables and then set the RS variable to whatever you want like this. It would be easier to just use the “-F” parameter though.

ps -ef | awk -v FS=: '{print $1}'

You can set the field separator to a slash like this:

ps -ef |awk -F/ '{print $3, $5}'

You could set it to a comma like this:

ps -ef |awk -F, '{print $3, $5}'

You can also change it to an arbitrary multi character string. Here are two examples setting it to “00” and “kworker”:

ps -ef |awk -F00 '{print $1, $2}'
ps -ef |awk -Fkworker '{print $1, $2}'

You can also specify a character class as a field separator. This example will split on either a “:” or on a “?”.

ps -ef |awk -F'[:?]' '{print $1, $2, $3}'