Re: [Ask] About awk
On Saturday, 18 August 2012 19:40:02 UTC+1, Morning Star wrote:
> Hi guys,
> I have some string and numeric data in like this format (one line):
> 1 2 3 4 5 6 7 8 9 10 11 12
> and i want the output like this:
> 1 2 3
> 4 5 6
> 7 8 9
> 10 11 12
>
>
>
> How do I do that in awk?
>
>
> Thanks in advance.
>
>
> Greetings,
>
>
> Marco
Marco,
Does the following work for you?
BEGIN {
splitat = 3
}
{
for (i = 0; i <= NF; i++) {
printf("%s ",$i)
if ((i % splitat) == 0) printf("\n")
}
}
Put into a file called split.awk and run with "awk -f split.awk your_input_file_name".
-mark
Reply to: