Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
4  
cut -d, -f2-7 –  Stéphane Chazelas Jan 18 at 18:22
    
man, I love you. You are a genius!!!!! Please add this comment as an answer! –  SpaceDog Jan 18 at 18:31
    
FYI, the format is called CSV (Comma Separated Values). –  goldilocks Jan 18 at 18:32
    
@goldilocks, thanks! –  SpaceDog Jan 18 at 18:33

1 Answer 1

up vote 3 down vote accepted
cut -d, -f 2-7 filename

or

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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