Simple sed question.

I have a log output with a format similar to this:

a=1, b= 2
c=0, d= 45, e=100

... and so on.

I figure I can just use awk or something to pipe the file to sed, but I'm trying to replace all the values above with 0.

I've tried:

cat blah | sed 's/=\(.*\),/0/'

but that didn't work. Any ideas?

Thanks.

$ sed 's/=\( *[0-9]*\)/=0/g' file
a=0, b=0
c=0, d=0, e=0
$ sed 's/[0-9][0-9]*/0/g' blah
a=0, b= 0
c=0, d= 0, e=0

Hi,

Another one:

sed 's/\(=[^0-9]*\)[0-9]\+/\10/g' infile

Regards,
Birei

Never assume? This works for any string after the = until you hit white space, end of line, comma or semicolon, like ="${boo#*xyz}":

sed 's/=[^ \t,;]*/=0/g'

We often assume from small data samples provided here, which is a real bad habit in the real world. In the real world, it is good to do some data checking with as big a data set as possible.

Of course, the requirements are just as terse! That is where active listening comes in!

oops:

$ cat infile
name="John Doe", a=1 , b=15 , c=102
name="Jane Doe", a=2 , b=7 , c=102

$ sed 's/=[^ \t,;]*/=0/g' infile
name=0 Doe", a=0 , b=0 , c=0
name=0 Doe", a=0 , b=0 , c=0

As you say without complete data we could be dealing with anything.

sed 's/=[^,]*/=0/g' infile
1 Like