Come on RudiC and rdrtx1,
In awk
$x
is the contents of a field in a line and that field might or might not be a number.
Note that the output of the command wc -l b.txt)
will be something like:
3465 b.txt
if the file b.txt
contains 3465 lines (AKA records) of text. With that, the command:
awk -F "\t" 'NR>5 {if (x==8) print $0}' x=$(wc -l b.txt) a.txt
would invoke awk
with the arguments:
awk -F "\t" 'NR>5 {if (x==8) print $0}' x= 3465 b.txt a.txt
Shell variable assignments only happen in shell command line processing when they occur at the start of a command line. In a shell variable assignment, the leading spaces in the command substitution would be assigned to the variable, but when it appears as a parameter on a command-line after the utility name, the spaces before and after the line count in the output from wc
act as field separators.
Hi Geneanalyst,
One might guess that one of the following might do what you requested.
awk -F '\t' -v x=$(( $(wc -l < b.txt) + 0)) '(NR>5) { if(($x == "0/0")) { print $0} }' a.txt > a1.txt
or:
awk -F '\t' '
FNR == NR {
x++
next
}
(NR + x) > 5 {
if(($x == "0/0")) { print }
}' b.txt a.txt > a1.txt
or:
awk -F '\t' '
FNR == NR {
x++
next
}
(NR + x) > 5 && $x == "0/0"' b.txt a.txt > a1.txt
One might also guess that you don't really want the awk
variable x
to be the number of records in b.txt
, but instead want it to be the number of fields
in that file. If that is what you want, it is even more important than in many other cases to know what operating system and shell you're using because some versions of awk
have a nextfile
command and others don't.
And, as always, sample input files and desired output would help us help you.