I was just looking into this. What I've found is the following:
awk 'NR==FNR{a[$1];next}$1 in a{print $1}' F1 F2
NR==FNR -- this will only be true when in the first file
a[$1] use the first column to make array of file
next skip all the next blocks and process the next line
($1 in a) check in value in column on of second file
then print it
gawk 'FNR==NR {a[$1]++;next} ($2 in a) {print $2}'
So this is NR==FNR same as above
a[$1] s same as above
$2 in a -- is column $2 in the array of second file? then print it
awk 'FNR==NR {a[$1]++;next} ($2 in a) {print $2}' 2&file
[1] 7183
awk: cmd. line:1: fatal: cannot open file `2' for reading (No such file or directory)
t: command not found
[1]+ Exit 2 awk 'FNR==NR {a[$1]++;next} ($2 in a) {print $2}' 2
2&file would be some like this. Run awk with file name 2 , and if ok, the run command file
I would like to substitute file file with some that returns file two or more in on go.
@newbie2010
My awk does compare first and second column, and if equal print what is equal.
It does not care what row its in, just compare every number anywhere in the column.
Well, it means what it says... There's no file named '2'. If you want to give it some other, more valid filename, you are free to do so.
It takes the & to mean 'run this command in background and take the text after as a new command'.
I do not understand this. If you want awk to read the file twice, you tell it the file twice; that's how it works. But I don't think your question is crossing the language barrier very well.