#!/usr/bin/awk -f # awk program to reformat input into 4 equal-length tab-separated columns { line[NR] = $0 } END { rows = int (NR / 4) rem = NR % 4 c2 = rows ; c3 = (rows * 2) ; c4 = (rows * 3) if (rem) { c2 += 1 ; c3 += 1 ; c4 += 1 } if (rem > 1) { c3 += 1 ; c4 += 1 } if (rem > 2) { c4 += 1 } for (i = 1 ; i <= rows ; i++ ) { printf ( "%s\t%s\t%s\t%s\n", line[i], line [i + c2], line [i + c3], line [i + c4])} if (rem) { printf ( "%s", line [rows + 1]) } if (rem > 1) { printf ( "\t%s", line [rows + 1 + c2]) } if (rem > 2) { printf ( "\t%s", line [rows + 1 + c3]) } if (rem) { printf ( "\n") }}