Is it always awklost after changing a certain field in the information about the separator of output fields? What happens if there are several field separators and I want them to be restored?
For example, suppose I have a simple file examplethat contains:
a:e:i:o:u
If I just ran a awkscript that takes into account the input field separator, which prints every line in my file, like running
awk -F: '{print $0}' example
I will see the source line. If, however, I change one of the fields directly, for example. with
awk -F: '{$2=$2"!"; print $0}' example
I do not return a modified version of the original string, instead I see fields separated by default space separator, for example:
a e! i o u
I can return a modified version of the original by specifying OFS, for example:
awk -F: 'BEGIN {OFS=":"} {$2=$2"!"; print $0}' example
, , ?
, example :, ; , -F":|;" , OFS .
, example2,
a:e;i:o;u
awk -F":|;" 'BEGIN {OFS=":"} {$2=$2"!"; print $0}' example2
( -F"[:;]"),
a:e!:i:o:u
: ; ,
a:e!;i:o;u