Copy one column over another in a delimited file
Posted
by user275455
on Stack Overflow
See other posts from Stack Overflow
or by user275455
Published on 2010-04-20T16:05:44Z
Indexed on
2010/04/20
16:33 UTC
Read the original article
Hit count: 158
For instance, I needed to remove column 25 and replace it with a copy of column 22 in a simple csv file with no embedded delimiters. The best I could come up with was the awkward looking:
I would expect something like
awk -F, '{ for(x=1;x<25;x++){printf("%s,", $x)};printf("%s,",$22);for(x=26;x<59;x++){printf
("%s,", $x)};print $59}'
to work but cut doesn't seem to want to print the same column two times...
cut -d, -f1-24,23,26-59
Is there a more elegant way to do it using anything typicaly available in a linux shell environment?
© Stack Overflow or respective owner