Problems sorting a CSV with sort
Tony Arnold
tony.arnold at manchester.ac.uk
Thu Aug 8 22:17:25 UTC 2013
Johnny,
Never tried but there is a package called 'csvtool' which may help.
Maybe worth taking a look.
Regards,
Tony.
On 08/08/13 21:40, Johnny Rosenberg wrote:
> The problem is that some of the fields contain commas, but they are
> inside double quotes.
>
> Example:
> sort -t, -k1,1 -k3,3 -k2,2 SomeFile.csv > OutputFile.csv
>
> A line could look something like this:
> This is the first field,"This is, well, the second field",The third
> field could look like this
>
> That line has three fields:
> 1: This is the first field
> 2: "This is, well, the second field"
> 3: The third field could look like this
>
> But sort consider it to have five fields:
> 1: This is the first field
> 2: "This is
> 3: well
> 4: the second field
> 5: The third field could look like this
>
> How would you solve this?
>
> One idea is, that when I create SomeFile.scv in the first place, I
> create a TAB separated file instead. Then I sort it and finally I
> replace all TABs with commas…
> But that means an extra step when I create SomeFile.csv, which is not
> optimal (unless I automate the creation of the file).
>
> Other ideas?
>
>
>
>
> Johnny Rosenberg
>
--
Tony Arnold, Tel: +44 (0) 161 275 6093
Head of IT Security, Fax: +44 (0) 705 344 3082
University of Manchester, Mob: +44 (0) 773 330 0039
Manchester M13 9PL. Email: tony.arnold at manchester.ac.uk
More information about the ubuntu-users
mailing list