Originally Posted by rebelbuttmunch
A colleague solved it for me. Using a file with a column of sorted key values
for seq in `cat seqid_uniq_sort.txt`; do echo `cat file_2 | grep $seq && cat file_1.txt | grep $seq`; done
thanks for following up and posting the solution. Allow me some comments on the script where I think it can be improved.
Do not use 'for' to read lines of a file. Read the following link that covers the problem in more detail:
You do not need to 'cat' the files and then pipe them to grep. Just use
grep "$seq" filename
It is also good practice to double-quote variables.
Finally, here is an alternative that also works with your sample data and does not require a third index file.
paste <(sort -k2 file2) <(sort -k1 file)
However, the formatting looks a bit different. Your files have trailing blanks which are being kept. If this is not wanted then you could do something like
paste <(sort -k2 file2) <(sort -k1 file) | sed 's/[[:blank:]]\+/ /g'
The 'sed' will replace multiple SPACE/TAB with a single space.
Hope this helps.