forked from milc-qcd/milc_qcd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
headtail.pl
executable file
·43 lines (30 loc) · 948 Bytes
/
headtail.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#! /usr/bin/perl
# headtail
# C. DeTar 18 Oct 1997
# Copies lines from stdin to stdout starting with
# pattern1 and ending with pattern2, inclusive.
# Usage...
# headtail.pl patterna patternb patterna patternb ...
# where /patterna/ and /patternb/ are awk/sed-type regular expression strings
# Example
# headtail.pl '^POINT' 'RUNNING COMPLETED'
# starts at the first line beginning with POINT and ends at the line
# containing the string RUNNING COMPLETED anywhere in the line.
# The process continues from there searching for the next patterna
# and resumes copying until patternb, etc.
# If patternb is not found, copying continues to the end of file.
$start = 0;
$patterna = shift(@ARGV);
$patternb = shift(@ARGV);
while(<STDIN>){
if(/$patterna/){$start = 1;}
if($start){
print $_;
if(/$patternb/){
if($#ARGV < 0){exit;}
$start = 0;
$patterna = shift(@ARGV);
$patternb = shift(@ARGV);
}
}
}