I have a CSV file formatted like this:
A @ B @ C @ D @ E
It should have five columns, unfortunately, some are missing the last column, e.g.:
A @ B @ C @ D
How can I add an extra @
to the end of every line which is missing the last column?
Assuming that the spaces are part of the field contents and the delimiter is "@" alone (although other variations can easily be accommodated):
awk 'BEGIN {FS = OFS = "@"} {$5 = $5; print}' inputfile
AWK creates missing intervening fields. Setting a field value to itself preserves existing contents if the field already exists or sets it and any intervening created fields to empty strings.
$ cat inputfile
A @ B @ C @ D @ E
A @ B @ C @ D
A @ B @ C
$ awk 'BEGIN {FS = OFS = "@"} {$5 = $5; print}' inputfile
A @ B @ C @ D @ E
A @ B @ C @ D @
A @ B @ C @@
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