Quote:
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
|
Hi,
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:
http://mywiki.wooledge.org/DontReadLinesWithFor
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.
Code:
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
Code:
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.