awk OFS - Output Field Separator


Example

This variable is used to set the output field separator which is a space by default.

awk -F'=' 'BEGIN { OFS=":" } { print $1 }' file

Example:

$ cat file.csv 
col1,col2,col3,col4
col1,col2,col3
col1,col2
col1
col1,col2,col3,col4,col5

$ awk -F',' 'BEGIN { OFS="|" } { $1=$1 } 1' file.csv
col1|col2|col3|col4
col1|col2|col3
col1|col2
col1
col1|col2|col3|col4|col5

Assigning $1 to $1 in $1=$1 modifies a field ($1 in this case) and that results in awk rebuilding the record $0. Rebuilding the record replaces the delimiters FS with OFS.