forked from douglasgscofield/tinyutils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stripfilt
executable file
·49 lines (45 loc) · 1.25 KB
/
stripfilt
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
44
45
46
47
48
#!/usr/bin/awk -f
#
# Copyright (c) 2012, 2015 Douglas G. Scofield, Uppsala University
#
# This code is covered by the Gnu GPLv2, please see LICENSE.
# Bugs and suggestions to https://github.com/douglasgscofield/tinyutils/issues.
#
# Strip out header and comment lines, or pass through only header and comment lines.
# Also handles empty/blank lines with skip_blank=1 option.
#
# CHANGELOG
# 2013-05-15 : make FS and OFS be "\t" by default
# 2012-12-04 : create the script
BEGIN {
# parameters
FS = "\t";
OFS = "\t";
header = 1; # does the input have a header? if so how many lines?
skip_comment = 1; # skip '#' lines on input
skip_blank = 0; # skip empty lines or those only containing whitespace?
inverse = 0; # do we instead only print the header and comments?
}
{
if (NR <= header) {
if (inverse)
print;
next;
}
if (NR > header && inverse && ! skip_comment && ! skip_blank)
exit;
if (skip_comment && $0 ~ /^#/) {
if (inverse)
print;
next;
}
if (skip_blank && $0 ~ /^[ \t]*$/) {
if (inverse)
print;
next;
}
if (! inverse)
print;
}