GAWK removes FS | on output

I have the simple gawk script below. When the script runs in the output of all the ITM lines the FS is replaced with a space, the Non ITM lines retain the | field separator.

The ITM lines have many fields and I can't insert "|" between each field because some of the fields are blank.

Is there a simple way of keeping the FS?

Thanks,

Paul

# parse.awk -- script to substitute a field
BEGIN { FS="|";rs=nl;
}
{

if ($1=="ITM" && $5=="DIM" )
{
$5 = $25

}

print

}
END {
}

---------- Post updated at 01:23 PM ---------- Previous update was at 12:48 PM ----------

I needed to specify OFS="|"

1 Like

Set the OFS, see awk cheat sheet (.pdf)

FS=OFS="|"
1 Like