~dricottone/my-utils

ref: fbf20d48af8ae6a18e44aa89e58e47c09fe06147 my-utils/core/stop-at -rwxr-xr-x 346 bytes
fbf20d48Dominic Ricottone vimsplit update 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/awk -f

# stop-at
# ===========
# Usage: <command> | stop-at -v pattern='^-+$'
#
# Re-print until a pattern is matched

BEGIN {
  if (pattern == "" || inclusive !~ /^[01]?$/) {
    print "Usage: stop-at -v pattern=PATTERN -v inclusive=0|1"
    exit 1
  }
}
{
  if ($0 ~ pattern) {
    if (inclusive==1) print;
    exit 0
  }
  print $0
}