in reply to Print string next to pattern matching?
Try this
The regex match should match anything after the colon and by using $1 uses that match. Use your own file names also.
#!/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 |
In Section
Seekers of Perl Wisdom