Re: sed – need an example for ”\digit”
Johnny Rosenberg
gurus.knugum at gmail.com
Sun Feb 26 14:12:58 UTC 2012
2012/2/26 Michael Welle <mwe012008 at gmx.net>:
> Hello,
>
> Johnny Rosenberg <gurus.knugum at 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
ジョニー・ローゼンバーグ
More information about the ubuntu-users
mailing list