Re: do shell script- sed conundrum
Re: do shell script- sed conundrum
- Subject: Re: do shell script- sed conundrum
- From: Gnarlodious <email@hidden>
- Date: Fri, 17 Feb 2006 13:47:58 -0700
- Thread-topic: do shell script- sed conundrum
Title: Re: do shell script- sed conundrum
Entity Eric Geoffroy spoke thus:
> Starting text
> Title: King KongTitle: Godzilla
> Title: Mothra
So, to communicate effectively, you want to insert a newline character before every string "Title:" where it is not preceded by a newline.
You could say this:
set someText to quoted form of (do shell script "echo '
Title: King KongTitle: Godzilla
Title: Mothra
' |tr '\\r' '\\n' " without altering line endings)
do shell script "echo " & someText & " | sed 's|^Title:\\(.*\\)Title:\\(.*\\)$|Title:\\1+Title:\\2|' | tr '+' '\\n' "
This looks for 2 instances of “Title:” in the same line so it’s very specific. It inserts a dummy character before the second instance of “Title” which should be a character not used in the file (I used “+” here). Because sed has a hard time inserting newlines into lines, the text is piped through the tr command where all instances of the dummy character are translated to newlines.
But you might find the perl solution to be better :=)
In general, sed is a linewise command and not well suited to multilines, although there are ways around that limitation.
-- Gnarlie
_______________________________________________
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