FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Ubuntu > Ubuntu User

 
 
LinkBack Thread Tools
 
Old 02-26-2012, 07:38 AM
Michael Welle
 
Default sed – need an example for ”digit”

Hello,

Johnny Rosenberg <gurus.knugum@gmail.com> writes:

> http://www.delorie.com/gnu/docs/sed/sed_5.html
>
> On that page saw this:
>
> ”digit
> Matches the digit-th (...) reference in the regular expression.”
>
> But I failed to create an example that works.
> Anyone?

echo 'hello crude world' | sed -e 's/^([ehlo]+) ([^ ]*)(.*)$/1
x 2 x 3/


is a back reference to the n. occurrence of a pair of braces.

Regards
hmw

--
biff4emacsen - A biff-like tool for (X)Emacs
http://www.c0t0d0s0.de/biff4emacsen/biff4emacsen.html
Flood - Your friendly network packet generator
http://www.c0t0d0s0.de/flood/flood.html

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 02-26-2012, 09:22 AM
Johnny Rosenberg
 
Default sed – need an example for ”digit”

2012/2/26 Michael Welle <mwe012008@gmx.net>:
> Hello,
>
> Johnny Rosenberg <gurus.knugum@gmail.com> writes:
>
>> http://www.delorie.com/gnu/docs/sed/sed_5.html
>>
>> On that page saw this:
>>
>> ”digit
>> Matches the digit-th (...) reference in the regular expression.”
>>
>> But I failed to create an example that works.
>> Anyone?
>
> *echo 'hello crude world' | sed -e 's/^([ehlo]+) ([^ ]*)(.*)$/1
> *x 2 *x 3/
>
>
is a back reference to the n. occurrence of a pair of braces.
>
> Regards
> hmw

Oh… I'm so sorry for having bothered you with that question. Why?
Because I use that syntax all the time without any problems.
So what was the problem this time? I don't know, maybe I went up from
bed too early or something, but I totally misunderstood the text
”Matches the digit-th (...) reference in the regular expression.”. I
was so focused on using ”digit” after the first slash so I didn't
realise that this is the usual ”/digit after the second slash” that I
use all the time…

But now, a couple of hours later, when I read that text again, I can't
really see why I misunderstood that sentence in the first place… I
really feel stupid now, I can assure you that.

Okay, sorry for that. Next time I'll make sure I've been awake for a
couple of hours before I ask any questions.

By the way, I have an almost similar question, let's call it a follow
up question ant let's how it's not as stupid as the last one…

This works as expected:
~$ echo "This is a short sentence" | sed 's/[^ ]* [^ ]* //'
a short sentence
~$

However, I tried to make it somewhat shorter, by using the {digit}
syntax, but I failed again… I am not sure how to group ”[^ ]* ” in a
proper way. This does not work:
~$ echo "jag är en ko" | sed 's/([^ ]* ){2}//'
jag är en ko
~$

What I'm trying to do is to remove the two first words from a
sentence, if that wasn't obvious. This should work no matter how many
words there are in the sentence. Originally I tried to solve this with
awk, but I failed…


Kind regards

Johnny Rosenberg
ジョニー・*ーゼンバーグ

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 02-26-2012, 09:43 AM
Michael Welle
 
Default sed – need an example for ”digit”

Hello,

Johnny Rosenberg <gurus.knugum@gmail.com> writes:
[...]
> By the way, I have an almost similar question, let's call it a follow
> up question ant let's how it's not as stupid as the last one…
>
> This works as expected:
> ~$ echo "This is a short sentence" | sed 's/[^ ]* [^ ]* //'
> a short sentence
> ~$
>
> However, I tried to make it somewhat shorter, by using the {digit}
> syntax, but I failed again… I am not sure how to group ”[^ ]* ” in a
> proper way. This does not work:
> ~$ echo "jag är en ko" | sed 's/([^ ]* ){2}//'
> jag är en ko
> ~$
>
> What I'm trying to do is to remove the two first words from a
> sentence, if that wasn't obvious. This should work no matter how many
> words there are in the sentence.
well, depending on your shell and your sed you need to quote the { and
the }.

Regards
hmw

--
biff4emacsen - A biff-like tool for (X)Emacs
http://www.c0t0d0s0.de/biff4emacsen/biff4emacsen.html
Flood - Your friendly network packet generator
http://www.c0t0d0s0.de/flood/flood.html

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 02-26-2012, 01:12 PM
Johnny Rosenberg
 
Default sed – need an example for ”digit”

2012/2/26 Michael Welle <mwe012008@gmx.net>:
> Hello,
>
> Johnny Rosenberg <gurus.knugum@gmail.com> writes:
> [...]
>> By the way, I have an almost similar question, let's call it a follow
>> up question ant let's how it's not as stupid as the last one…
>>
>> This works as expected:
>> ~$ echo "This is a short sentence" | sed 's/[^ ]* [^ ]* //'
>> a short sentence
>> ~$
>>
>> However, I tried to make it somewhat shorter, by using the {digit}
>> syntax, but I failed again… I am not sure how to group ”[^ ]* ” in a
>> proper way. This does not work:
>> ~$ echo "jag är en ko" | sed 's/([^ ]* ){2}//'
>> jag är en ko
>> ~$
>>
>> What I'm trying to do is to remove the two first words from a
>> sentence, if that wasn't obvious. This should work no matter how many
>> words there are in the sentence.
> well, depending on your shell and your sed you need to quote the { and
> the }.
>
> Regards
> hmw

Thanks.
~$ echo "jag är en ko" | sed 's/([^ ]* ){2}//'
en ko
~$

Great!
It's not easy to remember what should be quote and what should not…


Kind regards

Johnny Rosenberg
ジョニー・*ーゼンバーグ

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 02-26-2012, 01:21 PM
Michael Welle
 
Default sed – need an example for ”digit”

Hello,

Johnny Rosenberg <gurus.knugum@gmail.com> writes:

> 2012/2/26 Michael Welle <mwe012008@gmx.net>:
[...]
> Thanks.
> ~$ echo "jag är en ko" | sed 's/([^ ]* ){2}//'
> en ko
> ~$
>
> Great!
> It's not easy to remember what should be quote and what should not…
now let's make a little bit more fun and use -r :

~> echo "jag är en ko" | sed -re 's/([^ ]* ){2}//'
en ko

Regards
hmw

--
biff4emacsen - A biff-like tool for (X)Emacs
http://www.c0t0d0s0.de/biff4emacsen/biff4emacsen.html
Flood - Your friendly network packet generator
http://www.c0t0d0s0.de/flood/flood.html

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 

Thread Tools




All times are GMT. The time now is 07:07 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org