jlope043 has asked for the wisdom of the Perl Monks concerning the following question:
Hello everyone, It has been awhile since I have used Perl, therefore I have lost some of my knowledge since I am not using it as often. I am trying to capture a line after skipping a variable of characters and whitespaces, my $find is at column 32 and I want to copy from there and there after for each line that matches my $find. I believe I as missing something or have something in the wrong place as the code works but I get zero results back. Thank you in advance.
use strict; my $find = '^(H0|HT)'; open (NEW, ">", "OUTPUT.txt" ) or die "could not open:$!"; open (FILE, "<", "INPUT.txt") or die "could not open:$!"; while (<FILE>) { print NEW if /^(.{32}$find)/; } close (FILE); close (NEW);
------------------- INPUT FILE: JANE, DOE HT000000000 123 50 70 80 JOHN, DOE JR H0000000000 123 50 70 80 WILLIAM, DOE HT000000000 123 50 70 80 ------------------- EXPECTED OUTPUT FILE: HT000000000 123 50 70 80 H0000000000 123 50 70 80 HT000000000 123 50 70 80
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Copy Line After Skipping Columns
by GotToBTru (Prior) on Nov 15, 2016 at 21:30 UTC | |
by jlope043 (Acolyte) on Nov 15, 2016 at 21:36 UTC | |
|
Re: Copy Line After Skipping Columns -- oneliner
by Discipulus (Canon) on Nov 16, 2016 at 09:14 UTC |