I HAD these 2 files:
file1
pictures.txt 5 ref2313 4 ref2345 3 ref5432 2 ref4244 1
dance.txt 6 ref2342 5 ref2352 4 ref0695 3 ref5738 2 ref4948 1
treehouse.txt 6 ref8573 5 ref3284 4 ref5838 3 ref4738 2 ref4573 1
file2
pictures.txt 1 3
dance.txt 2 4
treehouse.txt 3 5
what I wanted to do was compare them in such a way that only the numbers with the refernce numbers in file1, which are between the 2 numebrs in file2 would show up. (NOTE: all version 1's don't have a reference number) so:
output:
pictures.txt 3 ref5432 2 ref4244 1
dance.txt 4 ref0695 3 ref5738 2 ref4948
treehouse.txt 5 ref3284 4 ref5838 3 ref4738
and I had code
#!/bin/bash
/usr/bin/nawk 'NR==FNR {for (i=2;i<=NF;i+3) a[$1 FS $i]=$(i+1);next}
{printf $1 FS} {for (i=($3);i>=($2);i-=1) printf i FS a[$1 FS i] FS}{printf "\n"}' file1 file2
which worked fine! BUT!! now my input file, file1, has changed to:
file1
pictures.txt 5 ref2313 dn32334 4 ref2345 dn32334 3 ref5432 dn32334 2 ref4244 dn32334
dance.txt 6 ref2342 dn32334 5 dn32334 ref2352 4 dn32334 ref0695 3 ref5738 dn32334 2 dn32334 ref4948 1
treehouse.txt 6 dn32334 ref8573 5 ref3284 dn32334 4 ref5838 dn32334 3 dn32334 ref4738 2 dn32334 ref4573 1
so a dn numebr has been added to each version number (except version 1). The order on which the reference and dn appear may change for each one, but that doesn't matter. So I tried to edit my code to reflect this change:
new code:
/usr/bin/nawk 'NR==FNR {for (i=2;i<=NF;i+3) a[$1 FS $i]=$(i+1); b[$1 FS $i]=$(i+2) ;next}
{printf $1 FS} {for (i=($3);i>=($2);i-=1) printf i FS a[$1 FS i] FS b[$1 FS i] FS}{printf "\n"}' file1 file2
but this doesn't work!! as it only prints out whichever comes first for each version number out of the reference and dn number:
pictures.txt 3 ref5432 2 ref4244
dance.txt 4 dn32334 3 ref5738 2 dn32334
treehouse.txt 5 ref3284 4 ref5838 3 dn32334
and breath!!!!
Please help!
---------- Post updated at 04:23 PM ---------- Previous update was at 03:35 PM ----------
if anyone cares, I worked it out!
/usr/bin/nawk 'NR==FNR {for (i=2;i<=NF;i+3) (a[$1 FS $i]=$(i+1)) (b[$1 FS $i]=$(i+2)) ;next}
{printf $1 FS} {for (i=($3);i>=($2);i-=1) printf i FS a[$1 FS i] FS b[$1 FS i] FS}{printf "\n"}' file1 file2