Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Print string next to pattern matching?

by edimusrex (Monk)
on May 05, 2015 at 14:52 UTC ( #1125743=note: print w/replies, xml ) Need Help??

in reply to Print string next to pattern matching?

Try this

#!/usr/bin/perl use strict; use warnings; open FILE,"<file.txt"; my @array = <FILE>; close FILE; foreach(@array){ if(/^.+?:\s(.+)$/) { open NEW_FILE, ">>new_file.txt"; print NEW_FILE "$1\n"; close NEW_FILE; } }

The regex match should match anything after the colon and by using $1 uses that match. Use your own file names also.

Replies are listed 'Best First'.
Re^2: Print string next to pattern matching?
by sumathigokul (Acolyte) on May 06, 2015 at 02:48 UTC

    Hi edimusrex,

    The code is working exactly.... Thank you so much..

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2023-06-07 09:54 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (29 votes). Check out past polls.