Re: Sed replace oneline nogo in Applescript
Re: Sed replace oneline nogo in Applescript
- Subject: Re: Sed replace oneline nogo in Applescript
- From: BJ Terry <email@hidden>
- Date: Tue, 10 Feb 2004 10:52:11 -0800
Alright, so, as near as I can tell, this is what's happening:
the command -e '1N;s|</A>\\(\\n<A\\)|</A> \\• \\1|;P;$!N;D' takes
the next line of input and appends it to the pattern space. In doing
this, it causes sed to skip the counting of the next line, the first
time it does it. If you add "=;" to the beginning of any of the
commands, and run the whole thing on my test file:
<H3>dog1</H3>
<H3>dog2</H3>
<H3>dog3</H3>
<H3>dog4</H3>
<HR>
</A>
<A href=blach>
You get:
"1
<H3>dog1</H3>
3
<H3>dog2</H3>
4
<H3>dog3</H3>
5
<H3>dog4</H3>
6
<BR>
7
</A> •
7
<A href=blach>"
Ironically, the only line number that it skips is 2, which just happens
to be the address you were trying to use. In order to address 2 in your
script, all you have to do is use "3" instead, which causes this
output:
"<H3>dog1</H3>
<h3><a href=\"./\">dog2</H3>
<H3>dog3</a></h3>
<H3>dog4</H3>
<BR>
</A> •
<A href=blach>"
Only line number 2 has been substituted.
When you call 1N, which only runs the first time through, it increments
the line counter. After that, the pattern space consists of the first
two lines. The "P" function prints the first line of the pattern space,
then $!N pulls the next line from input, into the pattern space,
leaving three lines there, lines 1 2 and 3, and incrementing the line
counter (because line 3 was just read). D deletes the first line,
leaving only lines 2 and three. Thereafter, you're taking the lines
from the file two at a time, deleting the first line in the pattern
space and adding the next. So, the line number is always going to be
the line following the first line in the pattern space. Since you're
regexes all are basically trying only to match against the first line,
this is confusing.
BJ
On Feb 10, 2004, at 7:00 AM, Gnarlodious wrote:
Yes, BJ, your assumptions are correct.
It works when sent as a single command call, like what you did.
But when I concatenate the middle command it simply will not work:
do shell script "sed " & ,
"-e 's|<HR>|<BR>|' " & ,
"-e '2s|<H3>\\(.*\\)<\\/H3>|<h3><a href=\"\\.\\/\">\\1</a></h3>|'
" & ,
"-e '1N;s|</A>\\(\\n<A\\)|</A> \\• \\1|;P;$!N;D' " & ,
flipPOSIX & ">" & flopPOSIX
Removing the "2" operates on all lines in the file.
I can't figure this out, maybe it's a buffering issue?
OTOH, the output string when pasted in Terminal doesn't work either,
so that
excuses Applescript.
Thanks for the help.
-- Gnarlie
_______________________________________________
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.