how to replace 123} in the end of a line with the value incr $i?

how to replace 123} in the end of a line with the value incr $i?

Post by baumann... » Wed, 03 Nov 2004 16:10:48



in a mib file, it contains many lines as below:
   ::= {mibnode  1}

   ::= {mibnode  2}

   ::= {mibnode  3}

...

   ::= {mibnode  10}

...
now I want to replace the number with a given value specified in $i,
after replace the first one, $i increased, then replace the second
matched, etc.

how can I realize it?  btw, I want to use sed. because I only know it
a little(know nothing about awk, perl).

I use the fellowing sed statement, but it failed.

 sed -e "s/\(.*\)[0-9][0-9]*}$/\1117}/g" e.mib > d.mib

in the above case, I just want to replace all the numbers before }
with 177, it failed.

 
 
 

how to replace 123} in the end of a line with the value incr $i?

Post by Eric Moor » Wed, 03 Nov 2004 17:00:47



> in a mib file, it contains many lines as below:
>    ::= {mibnode  1}

>    ::= {mibnode  2}

>    ::= {mibnode  3}

> ...

>    ::= {mibnode  10}

> ...
> now I want to replace the number with a given value specified in $i,
> after replace the first one, $i increased, then replace the second
> matched, etc.

> how can I realize it?  btw, I want to use sed. because I only know it
> a little(know nothing about awk, perl).

> I use the fellowing sed statement, but it failed.

>  sed -e "s/\(.*\)[0-9][0-9]*}$/\1117}/g" e.mib > d.mib

> in the above case, I just want to replace all the numbers before }
> with 177, it failed.

sed is not very well suited for this task, so I suggest you use
awk or perl anyway.

awk -v nr=$i '{nr+=gsub(/[0-9]+/, nr, $0); print $0}' e.mib > d.mib

Eric