Advertisement
cwchen

script to manage linebreaks

Mar 13th, 2016
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.51 KB | None | 0 0
  1. #!/usr/bin/perl -n
  2.  
  3. if ($. % 4 == 1) {
  4.     chomp;
  5.     $block1 = $_;
  6. }
  7. elsif ($. % 4 == 2) {
  8.     chomp;
  9.     $block2 = $_;
  10. }
  11. elsif ($. % 4 == 3) {
  12.     chomp;
  13.     $block3 = $_;
  14. }
  15. elsif ($. % 4 == 0) {
  16.     chomp;
  17.     $block4 = $_;
  18.     print "$block1 $block3\n$block2 $block4\n";
  19.  
  20.     # Clean blocks
  21.     $block1 = "";
  22.     $block2 = "";
  23.     $block3 = "";
  24.     $block4 = "";
  25. }
  26.  
  27. END {
  28.     # Print out remaining blocks
  29.     if ($. % 4 != 0) {
  30.         print "$block1 $block3\n$block2 $block4\n";
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement