'Mawk - removing special characters

I use mawk.

I have a file:

{1: [u'Bank Pocztowy'], 2: [u'Pekao']}

I want to get the result:

{1: [uBank Pocztowy], 2: [uPekao]}

I tried this:

mawk '{gsub("\'",""); print}' file

Thank you for your help.

EDIT: Example:

$ mawk '{gsub("\'",""); print}' file
> 
awk


Solution 1:[1]

Your gsub should be as below:

gsub(/\047/,"" )

chekc with

mawk '{gsub(/\047/,""); print}' file

I dont have mawk installed here. i only have nawk:

tested with nawk:

> echo "{1: [u'Bank Pocztowy'], 2: [u'Pekao']}" | nawk '{gsub(/\047/,"" ) ; print}'
{1: [uBank Pocztowy], 2: [uPekao]}

Alternatively ,If you want the solution in perl :

> echo "{1: [u'Bank Pocztowy'], 2: [u'Pekao']}" | perl -pe "s/\'//g"
{1: [uBank Pocztowy], 2: [uPekao]}

Solution 2:[2]

UPDATE #2 : realized I could clean it up even more so

[gnm]awk 'gsub("\47",_)~_' 

If you really insists on using traditional/linting flag on gawk, i.e. gawk -te or gawk -ce, then do :

gawk -t NF=NF FS="'" OFS=''

   or even

gawk -c 1 RS="'" ORS=''

(UPDATE #1) EDIT : just realized it can be simplified to

[gnm]awk 'gsub(/\47+/,"")+!+""'

you can cut out the final print too, and make it go faster

 mawk/mawk2/gawk 'BEGIN { FS = "^$" } gsub(/[\047]+/, "") || 1'

Setting FS so not to spend time splitting fields. If single quotes exist, the gsub( ) return will handle the print automatically. The "or 1" is for the case when no single quotes exists that line.

Another method is use FS to detect the single quotes

 mawk/mawk2/gawk 'BEGIN { FS = "\047" } (NF == 1) || gsub(/[\047]+/, "")'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2