Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2021-01-23 09:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?