Ok so I wrote a small script that reads a file and extracts the <b>lines</b> that contain the matches I want to extract but I cannot seem to find a way to extract the matches out of those lines. When I run the script I get the following:
1
randomtext randomtext randomtext USER ID: 123456 randomtext
2
randomtext USER ID: 78910 randomtext randomtext randomtext
3
randomtext USER ID: 547695 randomtext USER ID: 345876 random
What I want is just one column of nothing but:
USER ID: 123456
USER ID: 78910
USER ID: 547695
USER ID: 345876
but I don't know how to get rid of everything else or how to tell Perl that all I want is just what has been matched, not the lines in which the match is contained.
This is my code:
Any help is greatly appreciated. Thanks!
1
randomtext randomtext randomtext USER ID: 123456 randomtext
2
randomtext USER ID: 78910 randomtext randomtext randomtext
3
randomtext USER ID: 547695 randomtext USER ID: 345876 random
What I want is just one column of nothing but:
USER ID: 123456
USER ID: 78910
USER ID: 547695
USER ID: 345876
but I don't know how to get rid of everything else or how to tell Perl that all I want is just what has been matched, not the lines in which the match is contained.
This is my code:
Code:
open(INFILE, 'userdata.txt') or die "The file could not be found.";
$count = 0
while(<INFILE>) {
$TheLine = $_;
$chomp($TheLine);
foreach($TheLine =~ /USER ID/) {
open(OUTFILE, ">>UserIDs.txt");
print OUTFILE "$_\n";
print OUTFILE "$TheLine\n\n"; { next }
$count += 1;
print OUTFILE "Line Count";
}
}
print "There were $count matches"
Any help is greatly appreciated. Thanks!