dat2h.awk (512B)
1 #!/usr/bin/awk -f 2 3 function printchars() { 4 while (n > 0) { 5 x = n / 16 >= 1 ? 16 : n; 6 printf("0x%x%x,%s", x - 1, ref[c] - 1, ++i % 12 == 0 ? "\n" : " "); 7 n -= x; 8 } 9 } 10 11 /^$/ { 12 printchars(); 13 printf("\n\n"); 14 c = ""; 15 i = 0; 16 } 17 18 /./ { 19 if (!ref[$0]) { 20 col[cnt++] = $0; 21 ref[$0] = cnt; 22 } 23 if ($0 != c) { 24 if (c != "") 25 printchars(); 26 c = $0; 27 n = 0; 28 } 29 n++; 30 } 31 32 END { 33 for (i = 0; i < cnt; i++) 34 printf("%s,%s", col[i], ++j % 4 == 0 || i + 1 == cnt ? "\n" : " "); 35 }