Solved

Remove links from file, special characters and integers.

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now