#!/bin/bash read -s h w awk -v FS='' '{ lines[NR] = $0 print lines[NR] if (x != 0) next; cnt = 0 for(i = 1; i <= NF; i++) cnt += ($i == "*" ? 1 : 0); if (cnt == 2) x = (NR != 1) ? i - 1 : i + 1; if (cnt == 1) x = i; } END { for (i = 1; i <= length(lines); i++) print(lines[i]); }' < /dev/stdin