I am using an 'awk' command like below, which prints the 4th columns of all .out files containing 'cake':
awk '/cake/{print $4}' ./*/*.out
My output is a column, say:
1
2
3
4
5
6
How can I reformat this to something that looks like:
1 4
2 5
3 6
or
1 3 5
2 4 6
i.e. have a set number of column elements (3 and 2 in the above cases).
Better yet, can I make it spit out the output as a csv file within the same command?
Thank you.
You can do it with
awk
itself, but I preferpr
for thisNote that the above will work even if your number of input rows isn't an exact multiple of the number of columns you want (note that there's 3 comma-separated fields even in the lines with empty fields):
See https://stackoverflow.com/a/56725768/1745001 for how to do the opposite, i.e. generate a number of columns given a specified number of rows.