I have a database of subgraphs that looks like this:
t # 3-231, 1
v 0 94
v 1 14
v 2 16
v 3 17
u 0 1 2
u 0 2 2
u 0 3 2
t # 3-232, 1
v 0 14
v 1 94
v 2 19
v 3 91
u 0 1 2
u 0 3 2
u 1 2 2
t # 3-233, 1
v 0 17
v 1 91
v 2 16
v 3 94
u 0 1 2
u 0 3 2
u 1 2 2
t # 3-234, 1
v 0 90
v 1 93
v 2 102
v 3 95
u 0 1 2
u 0 3 2
u 1 2 2
I would like to retrieve all transactions that contains the following patterns: 'u 0 1 2' and 'u 0 2 2' along with transaction id (ex. line starts with t #).
I used the following code to accomplish this job:
#!/usr/bin/perl -w
use strict;
my $input = shift @ARGV or die $!;
open (FILE, "$input") or die $!;
while (<FILE>) {
my @fields = ('t', 'u\ 0\ 1', 'u\ 0\ 2');
my $field_regex = join( "|", @fields );
my @field_lines;
push( @field_lines, $_ ) if ( /^(?:$field_regex) / );
last if @field_lines == @fields;
push @field_lines, "";
print join( "\n", sort @field_lines );
}
close FILE;
However, it retrieves patterns, when only one line match, such as:
t # 3-231, 1
u 0 1 2
u 0 2 2
t # 3-232, 1
u 0 1 2
t # 3-233, 1
u 0 1 2
t # 3-233, 1
u 0 1 2
My ultimate goal is to retrieve transactions that completely match to my regex, such as
t # 3-231, 1
u 0 1 2
u 0 2 2
Thank you for your help!
Olha