title: How to use AWK with string as a RS?
body: <p>I want to use AWK, but I don't seem to get the first record right. I hope anyone can help to get it right.</p>
  
  <p>I have this file, every record is 3 lines but sometimes it has 4 lines (so there is a $3 and $4). My goal is to print all three lines of each record, and if there is a forth line I want also to print the first 2 lines with the forth (without the 3rd).</p>
  
  <p>My strategy is to use a string ("Sequence: ") as a RS, and new line ("\n") for FS.</p>
  
  <p>My file looks like this:</p>
  
  <pre><code>Sequence: X92272_IGHV4-31*08_Homosapiens_F_V-REGION_140..429_290nt_1_____290+0=290_partialin3'__     from: 1   to: 290
  Start     End  Strand Pattern                 Mismatch Sequence
  184     192       + pattern:AA[CT]NNN[AT]CN        . aacccgtcc
  Sequence: X92273_IGHV4-31*09_Homosapiens_F_V-REGION_140..429_290nt_1_____290+0=290_partialin3'__     from: 1   to: 290
  Start     End  Strand Pattern                 Mismatch Sequence
  184     192       + pattern:AA[CT]NNN[AT]CN        . aacccgtcc
  Sequence: Z14235_IGHV4-31*10_Homosapiens_F_V-REGION_140..438_299nt_1_____299+0=299___     from: 1   to: 299
  Start     End  Strand Pattern                 Mismatch Sequence
  184     192       + pattern:AA[CT]NNN[AT]CN        . aacccgtcc
  Sequence: AB019439_IGHV4-34*01_Homosapiens_F_V-REGION_59657..59949_293nt_1_____293+0=293___     from: 1   to: 293
  Start     End  Strand Pattern                 Mismatch Sequence
  150     158       + pattern:AA[CT]NNN[AT]CN        . aatcaatca
  178     186       + pattern:AA[CT]NNN[AT]CN        . aacccgtcc
  Sequence: M99684_IGHV4-34*02_Homosapiens_F_V-REGION_311..603_293nt_1_____293+0=293___     from: 1   to: 293
  Start     End  Strand Pattern                 Mismatch Sequence
  150     158       + pattern:AA[CT]NNN[AT]CN        . aatcaatca
  178     186       + pattern:AA[CT]NNN[AT]CN        . aacccgtcc
  </code></pre>
  
  <p>With the following code I get a messed up first record, because the string is in the beginning of the file as well.</p>
  
  <pre><code>awk '{ RS="Sequence: "; FS="\n" }
  {
  if ($4 != "" )
      print $1,"\n",$2,"\n",$3,"\n",$1,"\n",$2,"\n",$4
  else
      print $1,"\n",$2,"\n",$3 ;
  }' short.txt &gt; test 
  </code></pre>
  
  <p>With output:</p>
  
  <pre><code>Sequence:
   X92272_IGHV4-31*08_Homosapiens_F_V-REGION_140..429_290nt_1_____290+0=290_partialin3'__
   from:
   Sequence:
   X92272_IGHV4-31*08_Homosapiens_F_V-REGION_140..429_290nt_1_____290+0=290_partialin3'__
   1
  Start     End  Strand Pattern                 Mismatch Sequence
   184     192       + pattern:AA[CT]NNN[AT]CN        . aacccgtcc
  
  X92273_IGHV4-31*09_Homosapiens_F_V-REGION_140..429_290nt_1_____290+0=290_partialin3'__     from: 1   to: 290
   Start     End  Strand Pattern                 Mismatch Sequence
   184     192       + pattern:AA[CT]NNN[AT]CN        . aacccgtcc
  Z14235_IGHV4-31*10_Homosapiens_F_V-REGION_140..438_299nt_1_____299+0=299___     from: 1   to: 299
   Start     End  Strand Pattern                 Mismatch Sequence
   184     192       + pattern:AA[CT]NNN[AT]CN        . aacccgtcc
  AB019439_IGHV4-34*01_Homosapiens_F_V-REGION_59657..59949_293nt_1_____293+0=293___     from: 1   to: 293
   Start     End  Strand Pattern                 Mismatch Sequence
   150     158       + pattern:AA[CT]NNN[AT]CN        . aatcaatca
   AB019439_IGHV4-34*01_Homosapiens_F_V-REGION_59657..59949_293nt_1_____293+0=293___     from: 1   to: 293
   Start     End  Strand Pattern                 Mismatch Sequence
   178     186       + pattern:AA[CT]NNN[AT]CN        . aacccgtcc
  M99684_IGHV4-34*02_Homosapiens_F_V-REGION_311..603_293nt_1_____293+0=293___     from: 1   to: 293
   Start     End  Strand Pattern                 Mismatch Sequence
   150     158       + pattern:AA[CT]NNN[AT]CN        . aatcaatca
   M99684_IGHV4-34*02_Homosapiens_F_V-REGION_311..603_293nt_1_____293+0=293___     from: 1   to: 293
   Start     End  Strand Pattern                 Mismatch Sequence
   178     186       + pattern:AA[CT]NNN[AT]CN        . aacccgtcc
  </code></pre>
  
  <p>So I thought I should remove the first "Sequence: " string from the input file, but that gives:</p>
  
  <pre><code>X92272_IGHV4-31*08_Homosapiens_F_V-REGION_140..429_290nt_1_____290+0=290_partialin3'__
   from:
   1
   X92272_IGHV4-31*08_Homosapiens_F_V-REGION_140..429_290nt_1_____290+0=290_partialin3'__
   from:
   to:
  Start     End  Strand Pattern                 Mismatch Sequence
   184     192       + pattern:AA[CT]NNN[AT]CN        . aacccgtcc
  
  X92273_IGHV4-31*09_Homosapiens_F_V-REGION_140..429_290nt_1_____290+0=290_partialin3'__     from: 1   to: 290
   Start     End  Strand Pattern                 Mismatch Sequence
   184     192       + pattern:AA[CT]NNN[AT]CN        . aacccgtcc
  Z14235_IGHV4-31*10_Homosapiens_F_V-REGION_140..438_299nt_1_____299+0=299___     from: 1   to: 299
   Start     End  Strand Pattern                 Mismatch Sequence
   184     192       + pattern:AA[CT]NNN[AT]CN        . aacccgtcc
  AB019439_IGHV4-34*01_Homosapiens_F_V-REGION_59657..59949_293nt_1_____293+0=293___     from: 1   to: 293
   Start     End  Strand Pattern                 Mismatch Sequence
   150     158       + pattern:AA[CT]NNN[AT]CN        . aatcaatca
   AB019439_IGHV4-34*01_Homosapiens_F_V-REGION_59657..59949_293nt_1_____293+0=293___     from: 1   to: 293
   Start     End  Strand Pattern                 Mismatch Sequence
   178     186       + pattern:AA[CT]NNN[AT]CN        . aacccgtcc
  M99684_IGHV4-34*02_Homosapiens_F_V-REGION_311..603_293nt_1_____293+0=293___     from: 1   to: 293
   Start     End  Strand Pattern                 Mismatch Sequence
   150     158       + pattern:AA[CT]NNN[AT]CN        . aatcaatca
   M99684_IGHV4-34*02_Homosapiens_F_V-REGION_311..603_293nt_1_____293+0=293___     from: 1   to: 293
   Start     End  Strand Pattern                 Mismatch Sequence
   178     186       + pattern:AA[CT]NNN[AT]CN        . aacccgtcc
  </code></pre>
  
  <p>So again the first record is messed up. Is there a solution to this problem? My expected output is as the last output (with or without the string "Sequence :"), but with the first record correct.</p>