Re: text item delimiter
Re: text item delimiter
- Subject: Re: text item delimiter
- From: "Mark J. Reed" <email@hidden>
- Date: Fri, 29 Apr 2005 11:08:27 -0400
On 4/29/05, Rob Stott <email@hidden> wrote:
On 29 Apr 2005, at 15:25, Ruby Madraswala wrote:
Is
this doable using text item delimiters, I tried it's not working. All I
want to do is search a text file replace all occurrence of 1 to a, 2 to
b.........................
I wouldn't do it using TIDs. Here's how I'd do it ...
tell
application "Finder"
set theFile to
quoted form of (POSIX path
of (choose file))
end
tell
set
theResult to do shell script
"cat " & theFile & " | sed 'y/abcdefghi/123456789/' | sed 's/j/10/g' | sed 's/k/11/g' | sed 's/l/12/g' | sed 's/m/13/g'
| sed 's/n/14/g' | sed 's/o/15/g' | sed 's/p/16/g'
| sed 's/q/17/g' | sed 's/r/18/g' | sed 's/s/19/g'
| sed 's/t/20/g' | sed 's/u/21/g' | sed 's/v/22/g'
| sed 's/w/23/g' | sed 's/x/24/g' | sed 's/y/25/g'
| sed 's/z/26/g'"
Ow.
...theres
almost certainly a better way that doesn't involve that many 'sed's for
multiple digits but I'm not sure how. Can anyone put me straight on
that one?
Sure. A few points.
1. "cat file | command" is always a waste of a process. You can just do "<file command", no "cat" required.
2. A single sed will take as many substitutions as you want: "sed -e
s/1/a/g -e s/2/b/g ..." If the from and to strings are more than
one character each, that's what you would do.
3. But if the from and to are really individual digits and letters,
especially if they're in sequence, the "tr" command is a better choice
than sed. "tr abcd 1234" will do the trick; you can also
abbreviate sequences and rewrite it as "tr [a-d] [1-4]".
r.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (
--
Mark J. Reed <
email@hidden>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden