Remove Multiple numbers from file.

Hi,

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

 
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...

sed 's/\([0-9]\{2,\}\)/ /g;s/   / /g' infile
sed 's/ \{0,1\}[0-9]*\(-\|$\| \)/ \1/g' infile

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.

 
 
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...

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:

$ 
$ 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

sed "s/[0-9\-]\{7,\}//" file

Dear Friend msalam65 ,

You can use the following coding for your requirement

use strict;
use warnings;
my $var;
open(FH,"<fil4")or die "can't open";
while($var=<FH>)
{
  chomp($var);
  $var=~s/[0-9]{2,}//g;
  print "$var\n";
}

Thanks durden_tyler. The perl command worked. Thanks again.