Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Print string next to pattern matching?

by edimusrex (Monk)
on May 05, 2015 at 14:52 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (1)
As of 2024-04-25 19:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found