Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Regex to remove data

by Athanasius (Abbot)
on Nov 06, 2012 at 14:13 UTC ( #1002479=note: print w/ replies, xml ) Need Help??


in reply to Regex to remove data

Something like this should do the trick:

#! perl use strict; use warnings; my @lines = <DATA>; s/ ^ [A-Z\s]+ $ //x for @lines; print for @lines; __DATA__ AAAAAAAA AAAA AAAAAAA AAAA AAA AAA Leave me intact PLEASE

Output:

0:10 >perl 369_SoPW.pl Leave me intact PLEASE 0:13 >

Update 1: Note that this will also remove blank (i.e. empty) lines.

Update 2: Changed

print "@lines";

to

print for @lines;

to address the issue of leading spaces raised by Anonymous Monk, below.

Hope that helps,

Athanasius <°(((><contra mundum


Comment on Re: Regex to remove data
Select or Download Code
Replies are listed 'Best First'.
Re^2: Regex to remove data
by rjt (Deacon) on Nov 06, 2012 at 17:19 UTC

    This is good, but the OP did say he wanted to remove the lines from a "large file", but your approach reads the entire file into an in-memory array (@lines) and processes that.

    Check out my reply below for an example that loads only one line into memory at a time (the -n switch assumes while (<>)).

Re^2: Regex to remove data
by Anonymous Monk on Nov 06, 2012 at 14:23 UTC
    Thanks,though it adds a leading space to each line

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1002479]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (17)
As of 2015-07-30 15:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (272 votes), past polls