Problem
I want to parse some data structured as lines (\n separated) with fields separated by the NUL character \0.
Many linux commands handle this separator with options such as --zero for find, or -0 for xargs or by defining the separator as \0 for gawk.
I didn't manage to understand how to make column interpret NUL as separator.
Example
If you generate the following set of data (2 lines with 3 columns, separated by \0):
echo -e "line1\nline2" | awk 'BEGIN {OFS="\0"} {print $1"columnA",$1"columnB",$1"columnC"}'
You would get the expected following output (\0 separators won't be displayed but is separating each field):
line1columnAline1columnBline1columnC
line2columnAline2columnBline2columnC
But when I try to use column to display my column, despite passing \0, the output for some reason only display the first column:
echo -e "line1\nline2" \ | awk 'BEGIN {FS="\0"; OFS="\0"} {print $1"columnA",$1"columnB",$1"columnC"}' | column -s '\0'
line1columnA line2columnA
Actually, even without providing the delimiter, column seems to break on the nul character:
echo -e "line1\nline2" \ | awk 'BEGIN {FS="\0"; OFS="\0"} {print $1"columnA",$1"columnB",$1"columnC"}' | column
line1columnA line2columnA
Question
- Is there a way to use
\0as a field/column separator incolumn? - Optional/ bonus question: Why does column behaves like this (I would expect the
\0to be totally ignored if not managed and the whole line to be printed as a single field) ? - Optional/ bonus question 2: Some data in these columns will be file paths and I wanted to use
\0as a best practice. Do you a have better practice to recommand for storing "random strings" in file without having to escape potential conflictual field separator character they may contain?
trto change them.""or\". In fact, why not use CSV? It's easy to work with, and most languages have decent libraries for parsing and outputting properly-formed CSV.