File: match-list-col.awk

package info (click to toggle)
tigr-glimmer 3.02-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 13,952 kB
  • ctags: 2,530
  • sloc: cpp: 24,376; awk: 232; csh: 220; makefile: 155; sh: 36
file content (38 lines) | stat: -rwxr-xr-x 940 bytes parent folder | download | duplicates (6)
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
#!/bin/awk -f
# Usage:  match-list-col.awk  <list-file>  <col>
#   Print lines from stdin whose entry in column <col> is one of the entries
#   occurring in <list-file>.

BEGIN   {
         if  (ARGC < 3)
             Usage();

         fp = ARGV [1];
         delete ARGV [1];
         while  ((getline < fp) > 0)
             {
              list [$1] = 1;
             }

         col = ARGV [2];
         delete ARGV [2];
         match (col, /[0-9]*/);
         if  (RSTART != 1 || RLENGTH != length (col))
             {
              printf "ERROR:  Bad column value = %s\n", col;
              Usage();
             }
        }

        {
         if  (list [$(col)] == 1)
             print;
        }

function  Usage  ()
  {
   print "# Usage:  match-list-col.awk  <list-file> <col>";
   print "#   Print lines from stdin whose entry in column <col> is one of the";
   print "#   entries occurring in <list-file>.";
   exit;
  }