Click here to Skip to main content
15,888,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there,

I'm using Cygwin to sort a csv file, but I can't get it to ignore the header any ideas?
sort -t',' -k5,2 c:\tmp\CI-tosplit.csv > c:\tmp\CI-DEN-sorted.csv


-t"," - seperator
-k5 column ,2 I thought meant start at line 2 but I guess i'm wrong.
Posted

1 solution

Try
tail -n 2 c:\tmp\CI-tosplit.csv | sort -t',' -k5 c:\tmp\CI-tosplit.csv > c:\tmp\CI-DEN-sorted.csv
to start from line 2

{Edit - took out the ,2 ... too cut&paste keen!]
 
Share this answer
 
v2
Comments
Paul Hayman 4-Jun-13 8:34am    
Sorry this is using windows:

'tail' is not recognized as an internal or external command,
operable program or batch file.
CHill60 4-Jun-13 9:15am    
sorry ... must have some additional stuff installed. I'll go ask and in the meantime will delete my (dodgy) solution so your post goes back into the Unanswered pot
Paul Hayman 4-Jun-13 9:10am    
Ah ok I got it, but the header is now the footer lol....
CHill60 4-Jun-13 9:17am    
try ...(head -n 1 c:\tmp\CI-tosplit.csv && tail -n +1 c:\tmp\CI-tosplit.csv | sort ... etc
Paul Hayman 4-Jun-13 9:31am    
OK Thanks so much, I think it's getting close but still not quite right:

C:\cygwin\bin\head -n 1 /cygdrive/c/tmp/CI-tosplit.csv && C:\cygwin\bin\tail -n +1 /cygdrive/c/tmp/CI-tosplit.csv | C:\cygwin\bin\sort -t',' -k5 /cygdrive/c/tmp/CI-tosplit.csv > c:\tmp\CI-DEN-sorted.csv

Gives error:
c:\tmp>C:\cygwin\bin\head -n 1 /cygdrive/c/tmp/CI-tosplit.csv && C:\cygwin\bin
\tail -n +1 /cygdrive/c/tmp/CI-tosplit.csv | C:\cygwin\bin\sort -t',' -k5 /cy
gdrive/c/tmp/CI-tosplit.csv 1>c:\tmp\CI-DEN-sorted.csv
fulfillment_line_item_id,groupon_number,order_date,merchant_sku_item,quantity_re
quested,shipment_method_requested,shipment_address_name,shipment_address_street,
shipment_address_street_2,shipment_address_city,shipment_address_stat,shipment_a
ddress_postal_code,shipment_address_country,gift,gift_message,quantity_shipped,s
hipment_carrier,shipment_method,shipment_tracking_number,ship_date,groupon_sku,c
ustom_field_value,permalink,item_name,vendor_id,salesforce_deal_option_id,groupo
n_cost,billing_address_name,billing_address_street,billing_address_city,billing_
address_stat,billing_address_postal_code,billing_address_country,purchase_order_
number,product_weight,product_weight_unit,product_length,product_width,product_h
eight,product_dimension_unit,customer_phone,incoterms,hts_code,3pl_name,3pl_ware
house_location,kitting_details,sell_price,deal_opportunity_id,shipment_strategy
/usr/bin/tail: write error

It's got the headers but not sure about the write error?? any Ideas?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900