Perhaps you could post what the output is you were expecting.
* matches to zero or more instances of teh previous character / expression.
from your expression
Code:
sed 's/a*b/cd/g' test.txt
valid matches would include:
Code:
b (as zero a's)
ab (as one a)
aab (as more than one a).
Code:
ab (matches as there is 1 a followed by a b. replaced with cd)
aab (more than one a followed by a b so replaced with cd)
abb (ab is matched and changed to cd. this leaves b which matches so is replaced by cd as well.)
a1234b (b is preceeded by zero a's so changed to cd)
a???b (b is preceeded by zero a's so changed to cd)
a b (b is preceeded by zero a's so changed to cd)
a is not b (b is preceeded by zero a's so changed to cd)
a (no match, must be followed by a b)
b (b is preceeded by zero a's so changed to cd)
Not sure why you did not get a match for lines 4 and 5. but it is doing what you want.
If you want it to match anything surrouned by a n 'a' and a 'b' you need to use:
where the .* be means any and as many characters as there are.