Skip to content
Advertisement

Partially replace string using ‘sed’ shell command

I need to delete the <#> in the following pattern:

vdd1a<1>  
vdd1b<2>  
vdd1c<3>  
....

Outputs should be like:

vdd1a  
vdd1b  
vdd1c  
...

I was trying to do this sed 's/(vdd1[a-z]*).<[0-9]>/1/' file1 > file2

But it gives me “vdd1” all the way.

How can I do it correctly?

Advertisement

Answer

The dot . after the paren is matching the letter after the 1. You need to get rid of it. I.e.,

sed 's/(vdd1[a-z]*)<[0-9]>/1/' file1 > file2

Alternatively, you can just replace the <[0-9]> with a blank pattern, i.e.,

sed 's/<[0-9]>//' file1 > filed
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement