How to extract columns from one file and move to another file without printing the columns?
I have a 2GB csv file called data.csv. I want to extract 5 columns from data.csv and move to a new file (preferably a new csv file).
How can I do that? Is there an awk command which allows me to do that without actually printing the columns?
Something along the lines of:
csv 1 3 4 6 7 <data.csv >new.csv
- assuming columns 1 3 4 6 and 7 of course! For RHEL and clones the command
csvis in EPEL and can be installed in the usual way. For Ubuntu and its friends try:
csvtool col 1,3,4,6,7 data.csv >new.csv
$ cat data.csv 1,2,3,4,5,6,7,8,9,0 q,w,e,r,t,y,u,i,o,p a,s,d,f,g,h,j,k,l z,x,c,v,b,n,m $ csvtool col 1,2,3,4,5 data.csv >new.csv $ cat new.csv 1,2,3,4,5 q,w,e,r,t a,s,d,f,g z,x,c,v,b
For that simple case without any
csv specific extravagances,
cut might do:
cut -d, -f1-5 file 1,2,3,4,5 q,w,e,r,t a,s,d,f,g z,x,c,v,b
or, for single non-contiguous fields,
cut -d, -f1,3,7 file 1,3,7 q,e,u a,d,j z,c,m
Redirect to the desired new