I'm transforming some data with awk (or gawk) and want to delete one of the input fields before printing the output again.
What I want to achieve is this:
~ $ echo 'field1,field2,field3' | awk -F, '{transform($1); delete($2); print $0;}'
new_field1,field3
I can't just assign an empty string to $2 because that leads to new_field1,,field3 (note the two commas).
I could explicitly print only the fields that I want but that's not very elegant because I've got far more field than 3 and also there are optional fields at the end (not shown here). That's why I prefer print $0. Just need to get rid of some fields first.
Any idea?