I have an export from postgresql table with multiple fields, including boolean (exported by postgresql as t
and f
character), and I need to import it in another database (monetdb) that won't understand t/f as bool values.
(EDIT removed spaces to reflect true file aspect and avoid angry comments - previously there was spaces displayed)
id|val_str|bool_1|bool2|bool_3|bool4|
1|help|t|t|f|t|
2|test|f|t|f|f|
...
As I cannot replace all occurence of t
/f
I need to integrate the field separator in my pattern.
I tried to use awk
to replace fields t
with TRUE
and f
with FALSE
:
awk -F'|' '{gsub(/\|t\|/, "|TRUE|"); gsub(/\|f\|/, "|FALSE|"); print;}'
This is working partially, as consecutive fields with a same value (|t|t|
) will have only the first occurrence replaced (|TRUE|t|
- as 2nd occurence is in fact t|
and not |t|
).
id|val_str|bool_1|bool2|bool_3|bool4|
1|help|TRUE|t|FALSE|TRUE|
2|test|FALSE|TRUE|FALSE|f|
...
Table has ~450 columns so I can't really specify the list of columns to be replaced, nor work in postgres to 'transform' boolean columns (I could but ...).
I could run the gsub()
twice, but I was looking for more elegant way to match the entire field content for all fields.
gsub(/^t$/, ...)
is not helping either as we are in the middle of a line most of the time.