Solved

Remove links from file, special characters and integers.

Posted on 2010-08-28
2
362 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 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.

733 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