Sed question

I need to replace the numbers with a new string.
How can I give a wildcard for the different # of numbers

sed '/abcdef/s/abcdef=*/abcdef=999999/'<foo>foo1

From: To:
abcdef=1234 abcdef=999999
abcdef=12345 abcdef=999999
abcdef=123456 abcdef=999999
abcdef=1234567 abcdef=999999
abcdef=12345678 abcdef=999999
abcdef=123456789 abcdef=999999
abcdef=1234567890 abcdef=999999

Thanks in advance!!
Brandt

 
sed '/abcdef/s/abcdef=[0-9]\+/abcdef=999999/' <foo >foo1

With the single [0-9] I don't pick up any lines. That is why I placed 4 [0-9] in a row, but I don't allways have 4 digits in number it would be unknown..

Thanks

Brandt

That's why I put \+ after [0-9]; it means one or more of the preceding character.

That is what I thought it ment but does not seem to work!! Solaris v10

Thanks

Try it without the backslash.

no go

ugh!!

Then use [0-9]* or [0-9][0-9]*.

echo "abcdef=123456" | sed 's/=[0-9]*$/=999999/'

Try the longhand for + :slight_smile:

$ cat foo
abcdef=
abcdef=1234
abcdef=12345
abcdef=123456
abcdef=1234567
abcdef=12345678
abcdef=123456789
$ sed '/abcdef/s/abcdef=[0-9]\{1,\}/abcdef=999999/' foo
abcdef=
abcdef=999999
abcdef=999999
abcdef=999999
abcdef=999999
abcdef=999999
abcdef=999999

That will also add 999999 to cases where there is no number after abcdef=

$ echo "abcdef=" |sed 's/=[0-9]*$/=999999/'
abcdef=999999

That may not be desired (or may be...).