Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Remove links from file, special characters and integers.

Posted on 2010-08-28
2
361 Views
Last Modified: 2013-12-26
Hi,

I'm having a tough time figuring out the easiest way to remove all special characters, URLs and integers from a central file. Any help would be greatly appreciated
0
Comment
Question by:faithless1
2 Comments
 
LVL 26

Accepted Solution

by:
wilcoxon earned 500 total points
ID: 33551591
Something like this should work...
#!/usr/local/bin/perl
use strict;
use warnings;
use Tie::File;
use Regexp::Common;

my @file;
tie @file, 'Tie::File', 'central_file' or die "could not tie file: $!";
foreach my $line (@file) {
    # remove integers
    $line =~ s{\b$RE{num}{int}\b}{}g;
    # remove URLs
    # $line =~ s{\b$RE{URL}\b}{}g; # doesn't actually exist yet
    $line =~ s{\b(?:https?|ftp|gopher|file):// # protocol
               (?:[\w\d%.+]+/?)* # dir/file
              \b}{}gx;
    # remove special characters - choose one of these methods
    $line =~ s{[^\w\d\s\-]}{}g; # any characters you want to keep
    $line =~ s{(?:\x1B|\x1C)}{}g; # any characters you want to get rid of
}
untie @file;

Open in new window

0
 

Author Comment

by:faithless1
ID: 33607244
Sorry for the late response. Thanks for the code!
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question