Line processing

If I have a line say like this

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

I want column 16 to be moved into column 4 and the rest same, like this

1 2 3 16 5 6 7 8 9 10 11 12 13 14 15

Using awk, I know that replacing $4 with $16 and typing all the column numbers will help. But, I have more than 100 columns and I can't type all of them. Is there an easy way to specify what column to copy into what and print the rest?

Thanks in advance

Why would you need to type all the column numbers?

awk '{$4=$16;$16=""}1' file
1 Like

Try this:

awk '{temp = $4; $4 = $16; $16 = temp} {print $0}' file
1 Like

Thanks this works. But, it even prints the 16th column too, which I don't want. How do I do it?

sorry, did not read your first thread clearly.. if you dont want to print 16th column, use this.. It same as the solution provided by "bartus11"

awk '{$4 = $16; $16 = ""} {print $0}' file
1 Like