Click here to Skip to main content
12,394,769 members (72,496 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: Cygwin CSV
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 4-Jun-13 2:21am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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!]
  Permalink  
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?
CHill60 4-Jun-13 9:50am
   
Not sure (and nowhere near a machine I can check this out myself unfortunately) but it could be the target file name being in "windows format" rather than unix-style. Can't remember how to get around that I'm afraid. If you drop the redirection to a file does the error "go away"?
Paul Hayman 5-Jun-13 8:00am
   
No Still get the error. arghhh I thought it woul dbe easy to sort a csv from command line.... I know it's windows but it's a work pc...
CHill60 5-Jun-13 8:36am
   
Comment crashed! If you can use a Windows cmd file instead of cygwin then you could try something like more c:\tmp\CI-tosplit.csv +2 | sort > c:\tmp\CI-DEN-sorted.csv
Paul Hayman 5-Jun-13 8:57am
   
Still no luck i'm afraid....

Creates a file with the following: 2 cells c:\tmp>C:\cygwin\bin\sort -t" " -k6,2 c:\tmp\test.csv 1>c:\tmp\test-sorted.csv"

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 4 Jun 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100