Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Sort lists in AppleScript using the Unix sort command' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Sort lists in AppleScript using the Unix sort command
Authored by: DougAdams on May 17, '04 12:22:32PM
Somebody could earn a pretty penny from me by providing some cool shell scripts for use with text munging in AppleScript. AS is great for pushing apps around, but text and database stuff is way too for it. Here's one of my faves:
to srch_and_replace(txt, srch, repl)
	considering case
		repeat until txt does not contain srch
			set txt to (do shell script "echo " & txt & "| sed -e 's|" & srch & "|" & repl & "|' ")
		end repeat
		return txt
	end considering
end srch_and_replace

log srch_and_replace("Head Hand", "H", "l")
Friend Gnarlodious tipped me off to the sed stuff. Yeah. Mentioned here not long ago was "Wicked Cool Shell Scripts" by Dave Taylor. Good stuff there, too.

[ Reply to This | # ]
search-and-replace with sed
Authored by: hopthrisC on May 18, '04 04:18:32AM
replace

set txt to (do shell script "echo " & txt & "| sed -e 's|" & srch & "|" & repl & "|' ")

with

set txt to (do shell script "echo " & txt & "| sed -e 's|" & srch & "|" & repl & "|g' ")

(there's only one additional g near the end) and you can get rid of that repeat loop entirely. "g" stands for global and means sed should replace every occurance off the search string in the input line.

That will make the script much faster, too.

[ Reply to This | # ]

Sort lists in AppleScript using the Unix sort command
Authored by: Cezary Okupski on May 17, '09 01:20:26PM
I highly recommend Satimage.osax extension for text manipulation including text replacement according to a regular expression http://www.satimage.fr/software/en/dictionaries/dict_satimage.html

[ Reply to This | # ]
Sort lists in AppleScript using the Unix sort command
Authored by: tedw on May 17, '09 01:46:32PM

I have to agree about the Satimage osax - I use one or another of its commands in almost every applescript I write.



[ Reply to This | # ]