Worked like a charm - thanks!! Could you briefly explain what the stuff following the prinf means? With printf, it seems you're printing column 1 and 2 side by side of 8 characters per column. Then it seems you're repeating this 4 times to get the next 3 sets of data. But how does it create a new line once 4 sets of data have been printed across?
In this case the whole piece of code is run for each line of input.
Line1:
This prints out columns 1 and 2 ($1 and $2) of the input line ... the '%8s' means they get printed out in 8 character columns left padded with spaces.
Line 2:
Once the line has been read and the first 2 columns have been printed we increment a counter by one.
Line 3:
This test to see if our counter variable (the one we just incremented) is a multiple of 4 or not. the '%' operator returns the remainder after dividing the 1st argument (a) by the second (4).
Line 4:
So if the remainder of "a/4" is zero (ie. it is divisible by 4) then we print a new line. The reason this works is that the 'print' command always prints a new line character as opposed to the printf command which doesn't. This has the effect of printing a new line every 4 lines of input.
I normally do stuff in perl not awk ... so I always forget about awk's built in variables
And yes ... awk is not C ... the final command termination is implicit. It doesn't harm to put it in though You also avoid questions like: You terminated all your commands with ';' except the last one ... why?
I replied with an awk script since that was what the original poster has tried.
Hey we can write a simple script for that.. just we need to get maximum no of columns in that file
then run below command till n ' n is the max no of cols in that file'
for i = 1 to n
$ cut -d' ' -f$i < here ur filename> | paste -s >> tmp
end
[ paste -s prints in serial order so there we are taking 1 col,2col,3col,,....ncol.. ]