just want someone confirm there is no error in my micro awk code below
* if given on "f" not exists in input, then print not exists
* if given on "f" exists and given on "s" is greater than number in file a, print 'too small'
Code:
$ cat a
200 /f1
300 /f2
500 /f4
$ awk -vf=/f5 -vs=400 'BEGIN {c=0} ($NF==f) {if ($1<s) print "too small";c++} END { if (c==0) print f" not exists" }' a
/f5 not exists
$ awk -vf=/f4 -vs=400 'BEGIN {c=0} ($NF==f) {if ($1<s) print "too small";c++} END { if (c==0) print f" not exists" }' a
$ awk -vf=/f4 -vs=500 'BEGIN {c=0} ($NF==f) {if ($1<s) print "too small";c++} END { if (c==0) print f" not exists" }' a
$ awk -vf=/f4 -vs=600 'BEGIN {c=0} ($NF==f) {if ($1<s) print "too small";c++} END { if (c==0) print f" not exists" }' a
too small
$ awk -vf=/f3 -vs=600 'BEGIN {c=0} ($NF==f) {if ($1<s) print "too small";c++} END { if (c==0) print f" not exists" }' a
/f3 not exists
$ awk -vf=/f2 -vs=600 'BEGIN {c=0} ($NF==f) {if ($1<s) print "too small";c++} END { if (c==0) print f" not exists" }' a
too small
$ awk -vf=/f2 -vs=200 'BEGIN {c=0} ($NF==f) {if ($1<s) print "too small";c++} END { if (c==0) print f" not exists" }' a
$ awk -vf=/f2 -vs=201 'BEGIN {c=0} ($NF==f) {if ($1<s) print "too small";c++} END { if (c==0) print f" not exists" }' a
$ awk -vf=/f2 -vs=301 'BEGIN {c=0} ($NF==f) {if ($1<s) print "too small";c++} END { if (c==0) print f" not exists" }' a
too small
$ awk -vf=/f2 -vs=300 'BEGIN {c=0} ($NF==f) {if ($1<s) print "too small";c++} END { if (c==0) print f" not exists" }' a
$
btw. could someone propose code with single variable for all desired in a, so instead of many awk commands with -vf=/fX -vs=NNN, run one with single variable with all to be checked, eg. comma separated:
-vexpected="/f2:300,/f4:400,/f5:200