I need to find (basically, grep) matching lines ignoring the first field from file1:
field1 field2 field3 field4 field5 field6
id1 carrot white small
id2 carrot
id3 potato black
id4 potato
in file2:
field1 field2 field3 field4 field5 field6
num1 carrot white small tasty xxx
num2 carrot black big bad yyy
num3 potato yellow large good zzzz
num4 potato black small bad aaaa
num5 potato green medium nasty bbbb
num6 carrot white big good cccc
and print ids from file1 in file2 into file3:
field1 field2 field3 field4 field5 field6 fieldx fieldy
num1 carrot white small tasty xxx id1 id2
num2 carrot black big bad yyy id2
num3 potato yellow large good zzzz id4
num4 potato black small bad aaaa id3 id4
num5 potato green medium nasty bbbb id4
num6 carrot white big good cccc id2
I was trying to write something like this:
> while read line
> do
> awk '{$1=""; print $0}' $line > $line.1
> grep $line.1 file2 | awk '{print $1}' > $line.otu_id
> awk '{print $line "\t" $line.otu_id}' >> file3
> done < file1
but don't know how to use variables right. Could you please help?
Thank you!