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

Recommended Answers

All 2 Replies

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!

Yes definitely it all makes sense now,

Thanks alot ! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.