unix - How to move all strings in one file that match the lines of another to columns in an output file? -


i have 2 files, each 1 column this:

file 1

chr1 106623434 chr1 106623436 chr1 106623442 chr1 106623468 chr1 10699400 chr1 10699405 chr1 10699408 chr1 10699415 chr1 10699426 chr1 10699448 chr1 110611528 chr1 110611550 chr1 110611552 chr1 110611554 chr1 110611560 

file 2

chr1 1066234 chr1 106994 chr1 1106115 

i want search file 1 each line of file 2 , pull out every line has exact string , put new file. want each search output in own column or line separated tabs. want every line in file 2. output this:

chr1 106623434  chr1 10699400   chr1 110611528 chr1 106623436  chr1 10699405   chr1 110611550 chr1 106623442  chr1 10699408   chr1 110611552 chr1 106623468  chr1 10699415   chr1 110611554                 chr1 10699426   chr1 110611560                 chr1 10699448      

$ cat tst.awk nr==fnr { tgts[++numtgts] = $0; next } {     (tgtnr=1; tgtnr<=numtgts; tgtnr++) {         tgt = tgts[tgtnr]         if ($0 ~ "^"tgt) {             numhits[tgtnr]++             maxhits = (numhits[tgtnr] > maxhits ? numhits[tgtnr] : maxhits)             hits[tgtnr,numhits[tgtnr]] = $0         }     } } end {     (hitnr=1; hitnr<=maxhits; hitnr++) {         (tgtnr=1; tgtnr<=numtgts; tgtnr++) {              printf "%-16s%s", hits[tgtnr,hitnr], (tgtnr<numtgts?ofs:ors)         }     } }  $ awk -f tst.awk file2 file1 chr1 106623434   chr1 10699400    chr1 110611528 chr1 106623436   chr1 10699405    chr1 110611550 chr1 106623442   chr1 10699408    chr1 110611552 chr1 106623468   chr1 10699415    chr1 110611554                  chr1 10699426    chr1 110611560                  chr1 10699448 

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -