I have the following file.csv
111111 | 111111 | 22222 | 44444 | 4445454 | 67554333 |
I can count the number of fields using the following
awk -F '|' '{print NF}' file.csv
in my database schema I have 33 fields, however some of the lines in my csv file has less than 33 fields therefore when I import the file, it complains about miss match.
using awk how can I go about adding NULL fields spreader by | in order to full up 33 rows
your help is highly appreciated.
Thank you
To add empty fields at the end of line:
awk -F'|' -v OFS='|' '{for(i=NF+1;i<=33;i++)$i=""}1' file.csv
This might work for you:
sed ':a;s/|/&/33;t;s/$/|/;ta' file.csv
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With