Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove bracket from a particular string

Tags:

sed

awk

If some text is like

cell (ABC)
(A1)
(A2)
function (A1.A2)

I want output as

cell ABC
A1
A2
function (A1.A2)

I want to remove bracket from each line of file except the present in function line. Using code

sed 's/[()]//g' file 

Removes bracket from each line. How can I modify the above code to get desired output.

like image 677
VIKAS CHOUDHARY Avatar asked Dec 11 '22 00:12

VIKAS CHOUDHARY


1 Answers

You can add a jump out condition to your sed command:

sed '/^function /b;s/[()]//g' file

Or, condition the substitute on not matching a function:

sed '/^function /!s/[()]//g' file
like image 188
perreal Avatar answered Feb 20 '23 04:02

perreal