Remove Multiple numbers from file.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove Multiple numbers from file.
# 1  
Old 02-22-2010
Remove Multiple numbers from file.

Hi,

I am trying to cleanup 7 or 10 digits numeric from the file. So for example :

Code:
 
Input :
 
3M Corporation
3M Inc. 888-356-8765 
3M Inc. 356-8765 
3M Inc. 3568765 
3M Inc. 356-8765 
3M 8883568765 Inc.  
 
Output : 
3M Corporation
3M Inc. - -
3M Inc. -
3M Inc. 
3M Inc. -
3M Inc.

I need help in this issue as I am not able to check for 7 bytes or 10 bytes of numeric. Please advise.

Thanks...
# 2  
Old 02-22-2010
Code:
sed 's/\([0-9]\{2,\}\)/ /g;s/   / /g' infile

# 3  
Old 02-22-2010
Code:
sed 's/ \{0,1\}[0-9]*\(-\|$\| \)/ \1/g' infile

# 4  
Old 02-22-2010
The issue with this solution is it is also removing 2 or more numbers which I not want it. I only want to remove numbers if it 7 or mor bytes.

Code:
 
 
sed 's/\([0-9]\{2,\}\)/ /g;s/   / /g' number.dat

Input : 
 
20M Corporation               
3M Inc. 888-356-8765          
3M Inc. 356-8765              
3M Inc. 3568765               
33M Inc.356-8765              
3M 8883568765 Inc.            
8883568765 3M Inc.            
WACHOVIA/WELLS FARGO E2677-010
620 WEST 152ND STREET ASSOC LLC
AETNA               NYC70  NY2

 
Output : 
 M Corporation
3M Inc.  - -
3M Inc.  -
3M Inc.
 M Inc. -
3M Inc.
  3M Inc.
WACHOVIA/WELLS FARGO E -
WEST  152ND  STREET  ASSOC  LLC
AETNA  NYC  NY

Please advise.

Thanks...

Last edited by msalam65; 02-22-2010 at 06:11 PM..
# 5  
Old 02-25-2010
Any help on this will be greatly appreciated as the code is working fine but cleaning out all numbers that are more than 1. I need it to be more than 7. Please advise.
# 6  
Old 02-25-2010
Quote:
Originally Posted by msalam65
Any help on this will be greatly appreciated as the code is working fine but cleaning out all numbers that are more than 1. I need it to be more than 7. Please advise.
Here's one way to do it with Perl:

Code:
$ 
$ cat number.dat
20M Corporation               
3M Inc. 888-356-8765          
3M Inc. 356-8765              
3M Inc. 3568765               
33M Inc.356-8765              
3M 8883568765 Inc.            
8883568765 3M Inc.            
WACHOVIA/WELLS FARGO E2677-010
620 WEST 152ND STREET ASSOC LLC
AETNA               NYC70  NY2
$ 
$ 
$ perl -lne 's/[\d-]{7,}//g; print' number.dat
20M Corporation               
3M Inc.           
3M Inc.               
3M Inc.                
33M Inc.              
3M  Inc.            
 3M Inc.            
WACHOVIA/WELLS FARGO E
620 WEST 152ND STREET ASSOC LLC
AETNA               NYC70  NY2
$ 
$

tyler_durden
# 7  
Old 02-25-2010
Quote:
Originally Posted by durden_tyler
Here's one way to do it with Perl:

Code:
$ 
$ cat number.dat
20M Corporation               
3M Inc. 888-356-8765          
3M Inc. 356-8765              
3M Inc. 3568765               
33M Inc.356-8765              
3M 8883568765 Inc.            
8883568765 3M Inc.            
WACHOVIA/WELLS FARGO E2677-010
620 WEST 152ND STREET ASSOC LLC
AETNA               NYC70  NY2
$ 
$ 
$ perl -lne 's/[\d-]{7,}//g; print' number.dat
20M Corporation               
3M Inc.           
3M Inc.               
3M Inc.                
33M Inc.              
3M  Inc.            
 3M Inc.            
WACHOVIA/WELLS FARGO E
620 WEST 152ND STREET ASSOC LLC
AETNA               NYC70  NY2
$ 
$

tyler_durden
In sed
Code:
sed "s/[0-9\-]\{7,\}//" file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove space before numbers in delimited file

Hi, I have a file which looks like this FORD|1333-1| 10000100010203| 100040507697|0002|356.45|5555| SSSSY|KKKKM|1000005|10| N096|10043| C987 I need the output to look like this FORD|1333-1|10000100010203|100040507697|0002|356.45|5555| SSSSY|KKKKM|1000005|10| N096|10043| C987 The leading... (8 Replies)
Discussion started by: wahi80
8 Replies

2. Shell Programming and Scripting

Remove '.' from file for numbers ending in '.'

Hi, I have numerous files which have data in the following format A|B|123.|Mr.|45.66|33|zz L|16.|33.45|AC.|45. I want to remove decimal point only if it is last character in a number. O/p should be A|B|123|Mr.|45.66|33|zz L|16|33.45|AC.|45 I tried this sed -e 's/.|/|/g' Problem... (6 Replies)
Discussion started by: wahi80
6 Replies

3. Shell Programming and Scripting

Remove multiple lines from a text file

Hi I have a text file named main.txt with 10,000 lines. I have another file with a list of line numbers (around 1000) of the lines to be deleted from main.txt file. I tried with sed but it removes only a range of line numbers. Thanks for any help!! (1 Reply)
Discussion started by: prvnrk
1 Replies

4. Shell Programming and Scripting

How to remove the numbers in a file in perl script?

Thanks (1 Reply)
Discussion started by: Raysf
1 Replies

5. Shell Programming and Scripting

Renaming file that has multiple numbers as filename

Hi I have a file with filename as "partition-setup-and-ipl.vtcmd.76217657132.9721536798" Now i need to move this file as "partition-setup-and-ipl.vtcmd.76217657132.9721536798_org" i tried with # ls | grep -E "partition-setup-and-ipl.vtcmd.+"... (2 Replies)
Discussion started by: Priya Amaresh
2 Replies

6. Shell Programming and Scripting

Split a file into multiple files based on line numbers and first column value

Hi All I have one query,say i have a requirement like the below code should be move to diffent files whose maximum lines can be of 10 lines.Say in the below example,it consist of 14 lines. This should be moved logically using the data in the fisrt coloumn to file1 and file 2.The data of first... (2 Replies)
Discussion started by: sarav.shan
2 Replies

7. Shell Programming and Scripting

Remove Numbers from file

I have a file that has some text that looks like this Some Text 1. More text 2. Different text Final Text I would like the remove the lines of text that start with the numbers. Some Text Final Text I have tried to use cat file.txt | grep -Ev 1. >... (9 Replies)
Discussion started by: icculus99
9 Replies

8. Shell Programming and Scripting

Remove multiple lines in the file

Hi, How to remove duplicate lines in the file. a ------ b c 24 23 a ---- c b (4 Replies)
Discussion started by: sandy1028
4 Replies

9. Shell Programming and Scripting

Command to remove numbers from beginning of txt file

Hello. I have the following issue: my txt file has the following format: train/dr4/fklc0/sx175.txt 0 80282 Severe myopia contributed to Ron's inferiority complex. train/dr4/fklc0/sx355.txt 0 42906 Dolphins are intelligent marine mammals. train/dr4/fklc0/sa2.txt With the... (1 Reply)
Discussion started by: li_bi
1 Replies

10. Shell Programming and Scripting

how to remove files with only numbers as file names?

Hi all, I have a bunch of files that are named like 12543, 467249877, etc all over some directories.These files are named only with numbers, they dont have any letters or special characters in their file names. Could you please help me out and give me some command/script to remove only those... (6 Replies)
Discussion started by: praveen_indramo
6 Replies
Login or Register to Ask a Question