Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Remove links from file, special characters and integers.

Posted on 2010-08-28
2
Medium Priority
?
366 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
[X]
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
2 Comments
 
LVL 27

Accepted Solution

by:
wilcoxon earned 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

604 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