|
|
Subject: RE: Adding text after first occurrence only - msg#00070
List: editors.sed.user
Was this page helpful?
Thread at a glance:
Previous Message by Date:
click to view message preview
Re: Adding text after first occurrence only
Toen wij Andre Marcanth kietelden, kwam er dit uit:
> Ruud H.G. van Tol:
>> An ugly one again:
>> sed -e '1,1 s:</p>:&<line 1>:; t' -e '1,/<\/p>/ s::&<line 2+>:'
>> (ugly, because the replacement-string is mentioned twice)
> It worked!! Thank you very much! I think I understood some things, but
> others I could not. What I didn't understand is:
>
> &
See man sed:
An ampersand (``&'') appearing in the replacement is replaced by
the string matching the RE.
> ; t
See man sed again:
[2addr]t [label]
Branch [...] if any substitu-
tions have been made since the most recent reading of an input
line or execution of a ``t'' function. If no label is
specified,
branch to the end of the script.
> &<line 2+> (How does this work?) <line 1> is what I want to add but
> didn't understand the &<line 2+ part>
It was meant as documentative. Just put whatever-replacement-you-
need in both:
sed -e '1,1 s:</p>:&<replacement>:; t' -e '1,/<\/p>/
s::&<replacement>:'
> I see you used : instead of /. This way we don't need to escape
> special characters, right?
Yes. In the addresses-part it works differently.
--
Grtz, Ruud
------------------------ Yahoo! Groups Sponsor --------------------~-->
$9.95 domain names from Yahoo!. Register anything.
http://us.click.yahoo.com/J8kdrA/y20IAA/yQLSAA/dkFolB/TM
--------------------------------------------------------------------~->
--
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/sed-users/
<*> To unsubscribe from this group, send an email to:
sed-users-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
Next Message by Date:
click to view message preview
Re: Adding text after first occurrence only
Toen wij Pement, Eric kietelden, kwam er dit uit:
> Andre asked:
>> I would like to add something to only the first ocurrence of </p>
> [from the sed FAQ]
> If you have GNU sed and a bash shell, the answer is this:
>
> sed '0,\|</p>| s|</p>|&-your-extra-text-|' infile >outfile
[from the same sed FAQ]
Without GNU sed:
sed -e '/<\/p>/ {s//&-extra-/;:loop' -e '$!N;$!bloop' -e '}'
(on the prompt you might need to escape the exclamation marks)
--
Grtz, Ruud
------------------------ Yahoo! Groups Sponsor --------------------~-->
$9.95 domain names from Yahoo!. Register anything.
http://us.click.yahoo.com/J8kdrA/y20IAA/yQLSAA/dkFolB/TM
--------------------------------------------------------------------~->
--
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/sed-users/
<*> To unsubscribe from this group, send an email to:
sed-users-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
Previous Message by Thread:
click to view message preview
Re: Adding text after first occurrence only
Toen wij Andre Marcanth kietelden, kwam er dit uit:
> Ruud H.G. van Tol:
>> An ugly one again:
>> sed -e '1,1 s:</p>:&<line 1>:; t' -e '1,/<\/p>/ s::&<line 2+>:'
>> (ugly, because the replacement-string is mentioned twice)
> It worked!! Thank you very much! I think I understood some things, but
> others I could not. What I didn't understand is:
>
> &
See man sed:
An ampersand (``&'') appearing in the replacement is replaced by
the string matching the RE.
> ; t
See man sed again:
[2addr]t [label]
Branch [...] if any substitu-
tions have been made since the most recent reading of an input
line or execution of a ``t'' function. If no label is
specified,
branch to the end of the script.
> &<line 2+> (How does this work?) <line 1> is what I want to add but
> didn't understand the &<line 2+ part>
It was meant as documentative. Just put whatever-replacement-you-
need in both:
sed -e '1,1 s:</p>:&<replacement>:; t' -e '1,/<\/p>/
s::&<replacement>:'
> I see you used : instead of /. This way we don't need to escape
> special characters, right?
Yes. In the addresses-part it works differently.
--
Grtz, Ruud
------------------------ Yahoo! Groups Sponsor --------------------~-->
$9.95 domain names from Yahoo!. Register anything.
http://us.click.yahoo.com/J8kdrA/y20IAA/yQLSAA/dkFolB/TM
--------------------------------------------------------------------~->
--
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/sed-users/
<*> To unsubscribe from this group, send an email to:
sed-users-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
Next Message by Thread:
click to view message preview
Re: Adding text after first occurrence only
Toen wij Pement, Eric kietelden, kwam er dit uit:
> Andre asked:
>> I would like to add something to only the first ocurrence of </p>
> [from the sed FAQ]
> If you have GNU sed and a bash shell, the answer is this:
>
> sed '0,\|</p>| s|</p>|&-your-extra-text-|' infile >outfile
[from the same sed FAQ]
Without GNU sed:
sed -e '/<\/p>/ {s//&-extra-/;:loop' -e '$!N;$!bloop' -e '}'
(on the prompt you might need to escape the exclamation marks)
--
Grtz, Ruud
------------------------ Yahoo! Groups Sponsor --------------------~-->
$9.95 domain names from Yahoo!. Register anything.
http://us.click.yahoo.com/J8kdrA/y20IAA/yQLSAA/dkFolB/TM
--------------------------------------------------------------------~->
--
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/sed-users/
<*> To unsubscribe from this group, send an email to:
sed-users-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|
|