-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathlwhich
executable file
·42 lines (37 loc) · 1.13 KB
/
lwhich
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
#!/usr/bin/awk -f
#
# Copyright (c) 2016 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.
#
# Reports which line contains a column having the given value
#
# CHANGELOG
# 2017-08-10 : add inverse= option
# 2016-07-27 : create the script
BEGIN {
# parameters
FS = "\t";
OFS = "\t";
header = 0; # does the input have a header? if so how many lines?
skip_comment = 1; # skip '#' lines on input
val = ""; # the value to match
col = 1; # which column do we lwhich?
inverse = 0; # print numbers of lines that do not contain the value in the specified column
}
{
if (NR <= header) { print; next; }
if (skip_comment && $0 ~ /^#/) { print; next; }
if (NF < col) {
print "on input line " NR " missing requested column" > "/dev/stderr";
next;
}
if ($(col) == val) {
if (inverse == 0)
print NR;
} else if (inverse == 1)
print NR;
}