I want to have exactly the same output in this post(Extract data in linux/unix above,but I have a new input file,which is below:ABCB11  4   ACE 11ABCB11  4   CHRM1   114ABCB11  4   CHRM2   115ABCB11  4   DRD2    158ABCB11  4   EGF 164ABCC8   5   ACE 11ABCC8   5   ADRA1A  21ABCC8   5   ADRA1B  22ABCC8   5   ADRA1D  23ABCC8   5   CHRM1   114Taking all the unique genes and creating the output.I want all rows to have fromid,after taking distinct values from both. The exact output is what I want below:ABCB11 = fromid=4,from=ABCB11ABCC8 = fromid=5,from=ABCC8ACE = fromid=11,from=ACECHRM1 = fromid=114,from=CHRM1CHRM2 = fromid=115,from=CHRM2DRD2 = fromid=158,from=DRD2EGF = fromid=164,from=EGFADRA1A = fromid=21,from=ADRA1AADRA1B = fromid=22,from=ADRA1BADRA1D = fromid=23,from=ADRA1D
Parse,Manipulate Data In linux/Unix
linux;sed;awk;grep
Assuming 4 columns, a two-pass solutionawk 'NR == FNR {if (s[$1]++ == 0){printf %s = fromid=%s, from=%s\n, $1, $2, $1}; next};!s[$3]++{printf %s = fromid=%s, from=%s\n, $3, $4, $3}' file fileABCB11 = fromid=4, from=ABCB11ABCC8 = fromid=5, from=ABCC8ACE = fromid=11, from=ACECHRM1 = fromid=114, from=CHRM1CHRM2 = fromid=115, from=CHRM2DRD2 = fromid=158, from=DRD2EGF = fromid=164, from=EGFADRA1A = fromid=21, from=ADRA1AADRA1B = fromid=22, from=ADRA1BADRA1D = fromid=23, from=ADRA1D