code_junkie

How can I extract lines of text from a file?

Nov 12th, 2011
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. *** Start (more text here)
  2.  
  3. *** Finish (more text here)
  4.  
  5. # flip-flop.pl
  6. use strict;
  7. use warnings;
  8.  
  9. my $start = qr/^*** Start/;
  10. my $finish = qr/^*** Finish/;
  11.  
  12. while ( <> ) {
  13. if ( /$start/ .. /$finish/ ) {
  14. next if /$start/ or /$finish/;
  15. print $_;
  16. }
  17. }
  18.  
  19. $ perl -i'copy_*' flip-flop.pl data.txt
  20.  
  21. cat yourFileHere | awk '{if (d > 0) print $0} /.*Start.*/ {d = 1}'
  22.  
  23. cat yourFileHere | awk '/.*Finish.*/ {d = 1} {if (d < 1) print $0}'
  24.  
  25. cat yourFileHere | awk '/.*Start.*/ {d = 1; next} /.*Finish.*/ {d = 0; next} {if (d > 0) print $0}'
  26.  
  27. csplit yourFileHere /Start/ /Finish/
  28.  
  29. csplit inputfile %^*** Start%1 /^*** Finish/ %% {*}
  30.  
  31. csplit $1 %^*** Start%1 /^*** Finish/ %% {*}
  32. mv -f xx00 $1
  33.  
  34. $ sed -i '/^*** Start/,/^*** Finish/d!' *
  35.  
  36. $ sed -i -e '/./,/^*** Start/d' -e '/^*** Finish/,/./d' *
  37.  
  38. #!/usr/bin/perl -w
  39. use strict;
  40. use Tie::File;
  41. my $Filename=shift;
  42. tie my @File, 'Tie::File', $Filename or die "could not access $Filename.n";
  43. while (shift @File !~ /^*** Start/) {};
  44. while (pop @File !~ /^*** Finish/) {};
  45. untie @File;
  46.  
  47. #!/usr/bin/perl -ni
  48. if(my $num = /^*** Start/ .. /^*** Finish/) {
  49. print if $num != 1 and $num + 0 eq $num;
  50. }
Add Comment
Please, Sign In to add comment