0

Hi,

I'm going over this topic in unix and i'd be glad if someone could explain this bit of script: sed 's/\(abc\)*/xyz/' so the input would be abcabcabc which results in xyz Also how come 'xyz' doesnt repeat 3 times because the input is 'abc' x 3 ?

Thanks in advance,

ymf

2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by ymf
0

sed 's/string1/string2/' replaces string1 with string2. the 's' signifies the substitution.

you are grouping the letters 'abc' i.e. (abc) using \(abc\) using the \ to escape the literal interpretation of the parenthesis.

The asterisk is used to signify one or more occurences of the group 'abc'.

It is the reason you are getting a single 'xyz' as the output.

type the same without the asterisk to see the change in output.

Hope it helps!

0

Yes definitely it all makes sense now,

Thanks alot ! :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.