Removing comma just from numbers

Hi Guys,

I want to remove commas from just the numbers in the file.
So both sides of the comma should be numbers.

Input file

Johan
1,234 nb
jan
123,3
hi, hello, bye
12,345,54
hejhej

Desired output:

Johan
1234 nb
jan
1233
hi, hello, bye
1234554
hejhej

Thanks a lot :slight_smile:

perl -pe 's/(?<=\d),(?=\d)//g' file
1 Like

What have you tried so far, where are you stuck? Show some effort please.

thanks, worked perfect,

and do you have any idea about this:

I want to delete both pattern1 and pattern2 from the lines that have pattern1 in a file.

---------- Post updated 11-22-11 at 07:12 AM ---------- Previous update was 11-21-11 at 10:32 PM ----------

there is a webpage that I want to extract it's data, I used grep sed and cut and now came up to point which is hard :slight_smile:

(cat file |grep -v  '[0-9]') ; (cat file|grep '[0-9]'| sed 's/,//g')
1 Like

with sed...

sed '
/[[:digit:]]/ {
                   s/,//g
                 }
' filename

In nawk ..

$ nawk '/[0-9]/{gsub(/,/,"")};1' infile