Split one column into three with awk

Macmillan Linux for windows
September 21, 2009 at 02:15:41
Specs: Linux i686
I want to convert

1
2
3
4
5
6
7
8
9

into

123
456
789

I've seen examples with awk using a[something]=a[something] but I can't make it work. Can anyone help please?


See More: Split one column into three with awk

Report •


#1
September 21, 2009 at 07:49:43
One way is to use awk's modulo operator:

#!/bin/bash

awk ' {
if(NR % 3 == 0 )
   printf("%s\n", $0)
else
   printf("%s", $0)
} ' datafile.txt


Report •
Related Solutions


Ask Question