Replacing a column in CSV file with another in bash
Posted
by
user2525881
on Stack Overflow
See other posts from Stack Overflow
or by user2525881
Published on 2013-06-28T16:15:02Z
Indexed on
2013/06/28
16:21 UTC
Read the original article
Hit count: 224
I have a csv file with a number of columns. I am trying to replace the second column with the second to last column from the same file. For example, if I have a file, sample.csv
1,2,3,4,5,6
a,b,c,d,e,f
g,h,i,j,k,l
I want to output:
1,5,3,4,5,6
a,e,c,d,e,f
g,k,i,j,k,l
Can anyone help me with this task? Also note that I will be discarding the last two columns afterwards with the cut function so I am open to separating the csv file to begin with so that I can replace the column in one csv file with another column from another csv file. Whichever is easier to implement. Thanks in advance for any help.
© Stack Overflow or respective owner