Replace pattern with new one

Hi, I have file as follows. And i want to remove {,} and ' from the line with :4488: to :-}.
INPUT FILE

:2020:WITCH13288008772
:4488:20131015INR250000,03
:5500:00000060020001752
{Mr. Chintan '
Add1}
.   { } Add2
:5518:WITC0000822
-} 

OUTPUT FILE

:2020:WITCH13288008772
:4488:20131015INR250000,03
:5500:00000060020001752
Mr. Chintan 
Add1
.     Add2
:5518:WITC0000822
-}

try

$ awk -F "'" '/^:4488:/{F=1} /^-\}/{F=0} F{gsub(/[{},]/,"");gsub(FS,"")}1 ! F{print}' file

:2020:WITCH13288008772
:4488:20131015INR25000003
:5500:00000060020001752
Mr. Chintan
Add1
.     Add2
:5518:WITC0000822
-}
1 Like

Hello,

An another approach.

awk -vs1="{" -vs2="'" '{sub(s1,X); sub(s2,Y)}1' file_name

Output will be as follows.

:2020:WITCH13288008772
:4488:20131015INR250000,03
:5500:00000060020001752
Mr. Chintan
Add1
.     Add2
:5518:WITC0000822
-}

Thanks,
R. Singh

try also:

awk '/^:4488:/,/^[-]}/ {if ($0 !~ /^[-]}$/) gsub(/[\x27{}]/,"")} 1' input

A sed one:

sed "/^:4488:/,/^-}/ {s/[{}']//g;/^-/s/$/}/;}" file

(although it would be much simpler, but for that final }!

just a quick observation...

Did you still need the...

}

...at the end, or...

-}

...or is this a clerical error on your part...

Another sed alternative:

sed -e '/^:4488:/,/^-}/!b' -e '//b' -e "s/[{}']//g"

Regards,
Alister

And another one:

awk -F"[{}']" '/^-}/{r=0} /:4488:/{r=1} r{$1=$1}1' OFS= file

Try

$ cat file
:2020:WITCH13288008772
:4488:20131015INR250000,03
:5500:00000060020001752
{Mr. Chintan '
Add1}
.   { } Add2
:5518:WITC0000822
-}
$ awk '!/^-\}/{gsub(/{|}|\x27/,x)}1' file

Resulting

:2020:WITCH13288008772
:4488:20131015INR250000,03
:5500:00000060020001752
Mr. Chintan 
Add1
.     Add2
:5518:WITC0000822
-}

@pamu he want to retain comma ,

Can you factor the significance of :4488: into your solution?

Thanks Scott ..

$ awk '/:4488:/{f=1} /^-\}/{f=0} f{gsub(/{|}|\x27/,x)}1' file
:2020:WITCH13288008772
:4488:20131015INR250000,03
:5500:00000060020001752
Mr. Chintan 
Add1
.     Add2
:5518:WITC0000822
-}