Removing comma just from numbers

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing comma just from numbers
# 1  
Old 11-21-2011
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

1,234 nb
hi, hello, bye

Desired output:

1234 nb
hi, hello, bye

Thanks a lot Smilie
# 2  
Old 11-21-2011
perl -pe 's/(?<=\d),(?=\d)//g' file

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 11-21-2011
What have you tried so far, where are you stuck? Show some effort please.
# 4  
Old 11-22-2011
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 Smilie
# 5  
Old 11-22-2011

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

Last edited by Scott; 11-22-2011 at 05:37 AM.. Reason: Code tags
This User Gave Thanks to suresh.boddepu For This Post:
# 6  
Old 12-06-2011
with sed...

sed '
/[[:digit:]]/ {
' filename

Last edited by Franklin52; 12-06-2011 at 09:21 AM.. Reason: Please use code tags for code and data samples, thank you
# 7  
Old 12-06-2011
In nawk ..
$ nawk '/[0-9]/{gsub(/,/,"")};1' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sum up formatted numbers with comma separation

I need to sum up the values in field nr 5 in a data file that contains some file listing. The 5th field denotes the size of each file and following are some sample values. 1,775,947,633 4,738 7,300 16,610 15,279 0 0 I tried the following code in a shell script. awk '{sum+=$5} END{print... (4 Replies)
Discussion started by: krishmaths
4 Replies

2. Shell Programming and Scripting

awk to parse comma separated field and removing comma in between number and double quotes

Hi Experts, Please support I have below data in file in comma seperated, but 4th column is containing comma in between numbers, bcz of which when i tried to parse the file the column 6th value(5049641141) is being removed from the file and value(222.82) in column 5 becoming value of column6. ... (3 Replies)
Discussion started by: as7951
3 Replies

3. UNIX for Dummies Questions & Answers

Awk: Wondering how to format numbers with comma

I have tried the following commands and can't get a number to format with commas: echo 1234567.12 |awk '{printf("%-12s %20s\n", $0, comma($0)) }' This prints out value 50000 without a comma for i in *13*; do (cd $i && du -sk . && echo $i);done|grep -v 0000|gawk -F OFS="," ' {SUM += $1}... (8 Replies)
Discussion started by: newbie2010
8 Replies

4. UNIX for Dummies Questions & Answers

Need help removing leading spaces from one field in comma seperated file

Using awk or sed, I'd like to remove leading spaces after a comma and before a right justified number in field 6. Sounds simple but I can't find a solution. Each field's formatting must stay intact. Input: 40,123456-02,160,05/24/2012,02/13/1977, 10699.15,0 Output:... (5 Replies)
Discussion started by: Scottie1954
5 Replies

5. Shell Programming and Scripting

Removing Numbers

Hi, Below is a scattered representation of numbers . 1 2 11 22 11 22 1 2 1 2 11 22 1 2 11 22 I need to display only the following sequence "" and delete of the remainder from the output. The output should look like (2 Replies)
Discussion started by: Ananth12
2 Replies

6. Shell Programming and Scripting

Removing Line numbers

Hi all, I have a file consisting of lines in such a format: separated by space and M1 EOS for fullstop (.) ] e.g M1 I M1 have M1 a M1 file M1 consisting M1 of M1 lines M1 in M1 such M1 a M1 format M1 EOS M2 This M2 is M3 an (4 Replies)
Discussion started by: my_Perl
4 Replies

7. UNIX for Dummies Questions & Answers

validate a pattern of numbers that are comma separated

Hi, I have a requirement wherein, I need to validate a user input of the numbers that are comma separated. E.g . The input should be in the format 1,2,3...n (count of numbers is not known) . The user has to mention the input in this format, else it should exit from the program. ... (5 Replies)
Discussion started by: 12345
5 Replies

8. Shell Programming and Scripting

sed removing comma inside double quotes

I have a csv file with lines like the followings 123456,"ABC CO., LTD","XXX" 789012,"DEF LIMITED", "XXX" before I bcp this file to database, the comma in "CO.," need to be removed first. My script is cat <filename> | sed 's/"CO.,"/"CO."/g' but it doesn't work. Can anyone here able to... (2 Replies)
Discussion started by: joanneho
2 Replies

9. UNIX for Dummies Questions & Answers

Removing comma after 3rd column

I have 10,000 lines to remove the commas after the 3rd column. Any help will be appreciated! Removing commas after the 3rd column Input aaaaa,bbbbb,cccccc,ddddddd aaaaa,bbbbb,cccccc aaaaa,bbbbb,cccccc,ddddddd,eeeeee aaaaa,bbbbb,cccccc,ddddddd,eeeeee,fffffff........(limit of comma is not... (13 Replies)
Discussion started by: buddyme
13 Replies

10. Shell Programming and Scripting

removing all numbers from file

I have one me.txt file like aaa 765 gfre 534 jhk 321 cvvb 98 hftg 2 bdg2 hfuk 65 etc.. now I want to remove all numbers form that file using shell script and out put will be printed in me1.txt output: aaa gfre jhk cvvb hftg bdg hfuk please help me. (2 Replies)
Discussion started by: rinku
2 Replies
Login or Register to Ask a Question

Featured Tech Videos