I've been given some code that is supposed to be working, but it doesn't, and i'm trying to understand why that is. I'm trying to learn bash and awk for that reason, but it's quite confusing to me. If someone could help me to understand this awk code I would be really happy.
cvgMids.txt
contains many lines of the following format
<http://rdf.freebase.com/ns/g.11b74p1stp> <http://rdf.freebase.com/ns/type.object.type> <http://rdf.freebase.com/ns/cvg.video_game_soundtrack> .
<http://rdf.freebase.com/ns/g.11bc4msmrn> <http://rdf.freebase.com/ns/type.object.type> <http://rdf.freebase.com/ns/cvg.cvg_developer> .
<http://rdf.freebase.com/ns/g.11bxxz28q6> <http://rdf.freebase.com/ns/type.object.type> <http://rdf.freebase.com/ns/cvg.computer_videogame> .
What is the point of
BEGIN{i=0;}
I don't see variable i being used in any of the following lines.What is
<(cat cvgMids.txt) <(gzip -dc freebase-rdf-latest.gz) > cvg_predicates.txt
for? I get that you put the files in the end of awk but it's confusing to me with all these parenthesis etc.
awk 'BEGIN{i=0;}
FNR == NR {
if($1 in a) next;
a[$1] = $1;
next
}
FNR<NR {
if($1 in a) {print $0;}}' <(cat cvgMids.txt) <(gzip -dc freebase-rdf-latest.gz) > cvg_predicates.txt
<()
, see https://unix.stackexchange.com/questions/294635/what-is-the-bash-file-contents-syntax-called/294636#294636 – muru Mar 08 '20 at 13:23print a[$1];
no, it doesn't - not for me - I get the first column as expected. – muru Mar 08 '20 at 13:25