|
|
Subject: Re: search for two patterns - msg#00071
List: editors.sed.user
> --- Frank Dietrich <ablesoft@xxxx> wrote:
>
> >
> > I want to get only the pattern.
> >
> > The file statusfile contains only one line with some status
> > informations. The line contains 'on-line' or 'off-line' on a
> > variable position. I want to get as result only 'off' or 'on'.
> >
> > This line will work for 'off-line'.
> >
> > sed -n 's/^.*\(off\)-line.*/\1/p' statusfile
> >
> > How must I change it to get 'on' or 'off', with an single sed
> command?
> >
sed -ne '
/\<o\(nn\)\{0,1\}-line\>/!s/.*\<o\([nf]\)\(\1\{0,1\}\)-line\>.*/o\1
\2/p
' yourfile
------------------------ 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/
Was this page helpful?
Thread at a glance:
Previous Message by Date:
click to view message preview
Re: [OT] Extract a block from file
--- In sed-users@xxxxxxxxxxxxxxx, "Ruud H.G. van Tol" <rvtol@xxxx>
wrote:
> Toen wij gudermez kietelden, kwam er dit uit:
>
> > Of course we can overcome these limitations but we trade off
> > readability (which already is at a premium w/ sed).
>
> Which is a premium: readability, or the trade off of it? <g>
>
> --
> Grtz, Ruud
I believe it's the readability even if you understand the
mechanics of 'sed'.
--
Gudermez.
------------------------ Yahoo! Groups Sponsor --------------------~-->
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/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: search for two patterns
You might try the sed t option, which branches after a
successful match. As a crude example:
s/off/off/
tloop1
s/on/on/
tloop2
b # this will skip to the end
:loop1
Do whatever on off lines
b
:loop2
Do whatever on on lines
b
On Sun, Oct 17, 2004 at 04:16:08PM +0200, Frank Dietrich wrote:
>
> Hello all,
>
> I want to get only the pattern.
>
> The file statusfile contains only one line with some status
> informations. The line contains 'on-line' or 'off-line' on a
> variable position. I want to get as result only 'off' or 'on'.
>
> This line will work for 'off-line'.
>
> sed -n 's/^.*\(off\)-line.*/\1/p' statusfile
>
> How must I change it to get 'on' or 'off', with an single sed command?
>
> thanks
> Frank
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
------------------------ Yahoo! Groups Sponsor --------------------~-->
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/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: search for two patterns
--- Frank Dietrich <ablesoft@xxxx> wrote:
>
> I want to get only the pattern.
>
> The file statusfile contains only one line with some status
> informations. The line contains 'on-line' or 'off-line' on a
> variable position. I want to get as result only 'off' or 'on'.
>
> This line will work for 'off-line'.
>
> sed -n 's/^.*\(off\)-line.*/\1/p' statusfile
>
> How must I change it to get 'on' or 'off', with an single sed
command?
>
it's trivial if your 'sed' supports the regex OR \| operator:
sed -ne 's/.*\<\(on\|off\)-line\>.*/\1/p' yourfile
or, incase you prefer the standard 'sed', then try this:
sed -ne '
/onn-line/!s/.*\<o\([nf]\)\(\1\{0,1\}-line\)\>.*/o\1\2/p
' yourfile
--
Gudermez
------------------------ Yahoo! Groups Sponsor --------------------~-->
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/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: search for two patterns
Hi Gudermez,
"gudermez" <sharma__r@xxxxxxxxxxx> wrote:
> > The file statusfile contains only one line with some status
> > informations. The line contains 'on-line' or 'off-line' on a
> > variable position. I want to get as result only 'off' or 'on'.
> >
> > This line will work for 'off-line'.
> >
> > sed -n 's/^.*\(off\)-line.*/\1/p' statusfile
> >
> it's trivial if your 'sed' supports the regex OR \| operator:
>
> sed -ne 's/.*\<\(on\|off\)-line\>.*/\1/p' yourfile
Thanks for your answer. I found the solution any hours after
posting. In all my tries I forgot to escape the '|'. The failure was
in front of the monitor. ;-)
But wath the different between yours an my solution?
sed -n 's/^.*\(off\|on\)-line.*/\1/p' statusfile
What the '<' and '>' mean?
Frank
------------------------ 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/
|
|