• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Sort Array by Column X
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sort Array by Column X


  • Subject: Re: Sort Array by Column X
  • From: Tommy Bollman <email@hidden>
  • Date: Thu, 22 Jul 2010 11:32:20 +0200

Hello Steve.

I'm only curious of why it is necessary to have that last space included, I'm just wondering why:

set sorted_file to do shell script ("tr -d \\\" < " & posix_path_to_csv & " | sort -n -t , -k " & column_id & " ")
                                                                                                                                                     ^^^^
On 21 Jul 2010, at 15:29, Steve Thompson wrote:

> The file extension CSV stands for "comma separated values" so it's fair to assume that the file contains values separated by commas. Although quotes are used to delimit strings you can't guarantee (in "standard" files) that every field will have quotes round it. So you couldn't reliably use "," as a delimiter.
>
> If all your text fields have quotes round them then the sort would still work as "a, "b, "c and so on would sort in the same order as if the quotes weren't there.
>
> Alternatively, get rid of the quotes before the sort
>
> set column_id to 2
> set posix_path_to_csv to "/Users/steve/testfile.csv"
>
> set sorted_file to do shell script ("tr -d \\\" < " & posix_path_to_csv & " | sort -n -t , -k " & column_id & " ")
>
> Steve
>
>
> On 21 Jul 2010, at 13:46, Richard Lake wrote:
>
>> Didn't try this as your delimiter is simply a comma whereas my fields having quote marks surrounding them.
>>
>> set column_id to 5
>> set posix_path_to_csv to POSIX path of ((path to scripts folder) & "formdb.csv" as string)
>> set delimiter to quoted form of (quote & "," & quote)
>>
>> set sorted_file to do shell script ("sort -n -t " & delimiter & " -k " & column_id & " " & posix_path_to_csv)
>>
>> Trying alternative delimiter strings, but keep facing the same error:
>>
>> error "sort: multi-character tab `\",\"'" number 2
>>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> AppleScript-Users mailing list      (email@hidden)
> Help/Unsubscribe/Update your Subscription:
> Archives: http://lists.apple.com/archives/applescript-users
>
> This email sent to email@hidden

Best regards



Tommy Bollman
--------------------------------------------------------------------------------------------------
Mollison's Bureaucracy Hypothesis:
	If an idea can survive a bureaucratic review
	and be implemented it wasn't worth doing.

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Sort Array by Column X
      • From: Steve Thompson <email@hidden>
References: 
 >Sort Array by Column X (From: Richard Lake <email@hidden>)
 >Re: Sort Array by Column X (From: Steve Thompson <email@hidden>)
 >Re: Sort Array by Column X (From: Richard Lake <email@hidden>)
 >Re: Sort Array by Column X (From: Steve Thompson <email@hidden>)
 >Re: Sort Array by Column X (From: Richard Lake <email@hidden>)
 >Re: Sort Array by Column X (From: Steve Thompson <email@hidden>)

  • Prev by Date: Re: Sort Array by Column X and a Question for All
  • Next by Date: Re: File size problem
  • Previous by thread: Re: Sort Array by Column X
  • Next by thread: Re: Sort Array by Column X
  • Index(es):
    • Date
    • Thread