Re: Sorting IP addresses - Progress
Re: Sorting IP addresses - Progress
- Subject: Re: Sorting IP addresses - Progress
- From: Graff <email@hidden>
- Date: Sun, 21 Dec 2003 23:40:29 -0500
The \ character is a special escape character for text strings in
AppleScript. You need to double it up in an AppleScript text string in
order get a literal \. This means you need to format the command as
follows:
do shell script "tr '\\r' '\\n' < unsortedfile | sort -n -t '.' -k
1,1 -k 2,2 -k 3,3 -k 4,4 | tr '\\n' '\\r' > sortedfile"
Note the \\r and \\n instead of \r and \n.
There is a little bit more info about handling text in the "do shell
script" command here:
<
http://developer.apple.com/technotes/tn2002/tn2065.html#Section3>
- Ken
On Dec 21, 2003, at 11:04 PM, Bill wrote:
In reality, the shell sort , i.e. "sort -n -t.
..." is the fastest method and I'd think also the
easiest to program.
The only caveat, the file has to have Unix ending, not Mac ending.
Deivy,
You may consider the shell command tr
tr '\r' '\n' < unsortedfile |sort -n -t '.' -k 1,1 -k 2,2 -k 3,3 -k
4,4 |tr '\n' '\r' > sortedfile
Briefly,
tr '\r' '\n' < unsortedfile
translate (convert) every return character to linefeed character from
the file named "unsortedfile",
sort -n -t '.' -k 1,1 -k 2,2 -k 3,3 -k 4,4
sort it :)
tr '\n' '\r' > sortedfile
translate every linefeed character to return character, output the
result to the file named "sortedfile"
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.