1

I have a comma-delimited giant file that was exported from a database. The file has this format

Date,n1,n2,n3,n4,n5,n6,color,type,reference
10-Jan-2000,344,13,21,2,55,3,"rose garden" ,3444,32
11-Jan-2000,324,3,1,21,5,23,"space green fox" ,3444,11
12-Jan-2000,34,23,31,22,5,34,"bourbon mars" ,3444,88

Notice that the color field is surrounded by quotes and has a space at the end. Don't ask me why.

I would like to end with a file that is just this:

n1,n2,n3,n4,n5,n6
344,13,21,2,55,3
324,3,1,21,5,23
34,23,31,22,5,34

what magic command should I type on terminal to get rid of the date, color, type and reference on all lines of that txt file?

  • 4
    cut -d, -f2-7 – Stéphane Chazelas Jan 18 '14 at 18:22
  • man, I love you. You are a genius!!!!! Please add this comment as an answer! – SpaceDog Jan 18 '14 at 18:31
  • FYI, the format is called CSV (Comma Separated Values). – goldilocks Jan 18 '14 at 18:32
4
cut -d, -f 2-7 filename

or

awk -F, '{OFS=","; print $2,$3,$4,$5,$6,$7}' filename

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.