Script to match strings that sometimes are splitted in 2 lines

Hello Scrutinizer,

Pat1 always will appear, but the couple pat1 and pat2 may not always happens.

So, when pat2 exists will belongs to the previous pat1 and should be printed in the same line. If the script found 2 pat1 consecutives it means pat2 doesn't
exist for that pat1.

So, my goal is print the couple pat1 and pat2 in the same line, just that,
Hoping that the script could handle a input file of 4GB.

Many thanks for your help so far.

Regards

So something like this then?

awk -v pat1="ff44.{6,18}321456.{8}.f(.){16}" -v pat2="038.{32,34}.+84(.){30}" '
  {
    b=p $0
  }
  match(b,pat1) {
    s=substr(b,RSTART,RLENGTH)
    sub(pat1,x)
  }
  match(b,pat2) {
    print s, substr(b,RSTART,RLENGTH)
    sub(pat2,x)
  }
  {
    p=$0 
  }
' file_128_1.txt

Hello Scrutinizer,

Thank you, but it seems is not printing correctly pat1 and pat2. Is not printing the correlative 000002 in pat 1(ff44000002...) and for example for the 000003 is printing pat2 when 000003 doesn't have a pat2 associated.

If you can open the file in a text editor and highlight the patterns, you can see that sometimes pat1 and pat2 are along 3 lines. So, pat1 could begin in line1 and pat2 could begin in line2, but could finish in line 3. And variables b and only are joining 2 lines, so this could generate issues
I think in the output.

Hello Scrutinizer,

I've been trying and happens this:

If I try with file_128_1.txt of 128 bytes per line (without spaces), could happen that the pat1 and pat2 be in more than 2 lines, then will be printed only pat1 in this case.

If I try with the same file as input, but extended from 128 bytes to 256 or 512 bytes per line (without spaces), could be more than one occurence of pat1 or pat2 or both in a single line. Then, the output is not correct.

Based on above, I don't know how to get correct output.

For reference, the correct ouput for the input file_128_1.txt is attached.

Regards