Awk: printing column using for loop

Hello:

I've input data:

Input data

--- 3:60069:C:T 60069 C T 1 0 0 1 0 0 1 0 0 1 0 0 1
--- 3:60079:A:G 60079 A G 1 0 0 0.988 0.012 0 1 0 0 1 0 0 1
--- rs186476240:60157:G:A 60157 G A 1 0 0 1 0 0 1 0 0 1 0 0 1

I edit/make first few columns before numbers (6th column) and want to print data as they are. Numbers start from 6th colimn (zero-one)

  awk '{out=""; for(i=6;i<=NF;i++){out=$out" "$i}; print 3,3":"$3":"$4":"$5,$3,$4,$5,$out}' pot.txt

wrong output:

3 3:60069:C:T 60069 C T --- 3:60069:C:T 60069 C T 1 0 0 1 0 0 1 0 0 1 0 0 1
3 3:60079:A:G 60079 A G --- 3:60079:A:G 60079 A G 1 0 0 0.988 0.012 0 1 0 0 1 0 0 1
3 3:60157:G:A 60157 G A --- rs186476240:60157:G:A 60157 G A 1 0 0 1 0 0 1 0 0 1 0 0 1
3 3:60189:A:G 60189 A G --- 3:60189:A:G 60189 A G 1 0 0 1 0 0 1 0 0 1 0 0 1
3 3:60197:G:A 60197 G A --- rs115479960:60197:G:A 60197 G A 1 0 0 1 0 0 1 0 0 1 0 0 1
3 3:60201:T:C 60201 T C --- 3:60201:T:C 60201 T C 1 0 0 1 0 0 1 0 0 1 0 0 1
3 3:60202:C:G 60202 C G --- rs28729284:60202:C:G 60202 C G 1 0 0 1 0 0 1 0 0 1 0 0 1
3 3:60322:G:A 60322 G A --- 3:60322:G:A 60322 G A 1 0 0 1 0 0 1 0 0 1 0 0 1
3 3:60337:G:A 60337 G A --- rs116791090:60337:G:A 60337 G A 1 0 0 1 0 0 1 0 0 1 0 0 1
3 3:60342:A:<CN0> 60342 A <CN0> --- 3:60342:A:<CN0>:0 60342 A <CN0> 1 0 0 1 0 0 1 0 0 1 0 0 1

Correct output needed:

3 3:60069:C:T 60069 C T 1 0 0 1 0 0 1 0 0 1 0 0 1
3 3:60079:A:G 60079 A G 1 0 0 0.988 0.012 0 1 0 0 1 0 0 1
3 3:60157:G:A 60157 G A 1 0 0 1 0 0 1 0 0 1 0 0 1
3 3:60189:A:G 60189 A G 1 0 0 1 0 0 1 0 0 1 0 0 1
3 3:60197:G:A 60197 G A 1 0 0 1 0 0 1 0 0 1 0 0 1
3 3:60201:T:C 60201 T C 1 0 0 1 0 0 1 0 0 1 0 0 1
3 3:60202:C:G 60202 C G 1 0 0 1 0 0 1 0 0 1 0 0 1
3 3:60322:G:A 60322 G A 1 0 0 1 0 0 1 0 0 1
3 3:60337:G:A 60337 G A 1 0 0 1 0 0 1 0 0 1 0 0 1
3 3:60342:A:<CN0> 60342 A <CN0> 1 0 0 1 0 0 1 0 0 1 0 0 1

Even if I start from i=7, I get input column repeated in the output.

Where's my code going wrong?

If you

fields twice you shouldn't be surprised them showing up twice in the output. Not understanding what you REALLY want, from your sparse spec and non-matching input - output files, how about

awk '{$1 = 3}1' file
3 3:60069:C:T 60069 C T 1 0 0 1 0 0 1 0 0 1 0 0 1
3 3:60079:A:G 60079 A G 1 0 0 0.988 0.012 0 1 0 0 1 0 0 1
3 rs186476240:60157:G:A 60157 G A 1 0 0 1 0 0 1 0 0 1 0 0 1

$out in awk takes the value of variable out converts to integer and returns the value of that field#.

Remove $ like this:

awk '{out=""; for(i=6;i<=NF;i++){out=out" "$i}; print 3,3":"$3":"$4":"$5,$3,$4,$5,out}' pot.txt

Hi Rudic:

Even if I do:

 awk '{out=""; for(i=6;i<=NF;i++){out=$out" "$i}; print $out}' pot.txt

This doesn't have any variables that print from first column.

print 3,3":"$3":"$4":"$5,$3,$4,$5

I'm making new string with $3":"$4":"$5 and then print column 3, 4,5

There's not column one that could be possible be printed with this code.

How did you come to this:?

awk '{$1 = 3}1' file

Please become accustomed to provide decent context info of your problem.

It is always helpful to carefully and detailedly phrase a request, and to support it with system info like OS and shell, related environment (variables, options), preferred tools, adequate (representative) sample input and desired output data and the logics connecting the two including your own attempts at a solution, and, if existent, system (error) messages verbatim, to avoid ambiguities and keep people from guessing.

By trying to understand your sparse specification and taking your sample input serious. The result seemed to comply to what you posted as desired output (although that was not derived from your input).