Monday, 15 February 2010

Using awk in if statements -


I have a data file that looks like this:

  1 1010 9 AA AA10123C CCCT10133A AAC1013434A ACAAC10140A ACCCTAAC10143C CTACCT1RS 144773400014444T TA1 10146 AC A10147GC  

in the example of "." In the second column, I would like to replace it with merged output of columns 1 and 4, such as:

  1 1: 101090 1010 9AA A1 1: 10123 0 10123 CCCT1 1: 10133 0 10133 A AAC 1 1: 10134 0 10134 A ACAAC 1 1: 10140 0 10140 A ACCCTAAC 1 1: 10143 0 10143 C CTACT 1 RS 144773400 0 10144 T TA1 1 10146 0 10146 AC A1 1: 10147 0 10147 GC  

I was trying to do this with an if / again statement ... but I know that syntax is wrong, I am not sure how wrong it is.

  if [$ 2-au "." / Data / pathfile] then awk '{print $ 1 ":" $ 4}' and awk '{print $ 2}' & gt; & Gt; "/ Data / cleanfile" fi  

What am I missing?

You can do it yourself through awk.

  awk -v "{$ 2 = $ 1": "$ 4} {$ 1 = $ 1} 1 'file  

  $ awk '$ 2 == "AA1 1: 10123 0 10123 C CCTT 1 1: 10133 0 10133 A AAC 1 1: 10134 0 10134 A ACAAC 1 1 10140 0 10140 A ACCCTAAC 1 1: 10143 0 10143 C CTACT 1 RS 144773400 0 10144 T TA1 1: 10146 0 10146 AC A 1: 10147 0 10147 GC  
< / Html>

No comments:

Post a Comment