echo "field one has spaces | field two has spaces" \ | awk ' BEGIN { FS="|" } { print $2 print $1 # or what ever you want }'
You can also reduce this value to
awk -F'|' { print $2 print $1 }'
Edit In addition, not all awks can accept a multi-character regular expression for an FS value.
Edit2 Somehow I skipped this initially, but I see that you are trying to include \x00 in the char classes pre and post | char. I assume you mean \x00 == null char? I don't think you can have awk parsing a file with nested null characters. You can prepare your input, for example
tr '\x00' ' ' < file.txt > spacesForNulls.txt
OR delete them altogether with
tr -d '\x00' < file.txt > deletedNulls.txt
and eliminate this part of your regular expression. But, as stated above, some awk do not support regex for the FS value. And I don't use the tr trick very often, you may find that null char requires a slightly different notation, depending on your version of tr .
Hope this helps.
source share