function ts() {
    local mat;mat=(`dd`)
    local H;H=${#mat[@]}
    local W;W=${#mat[0][@]}
    for ((w=0;w<W;++w))
    do
        local tmp;tmp=''
        for ((h=0;h<H;++h))
        do
            tmp=$tmp${mat[h]: w: 1}
        done
        echo $tmp
    done
}

read H W
grep '#' | ts | grep '#' | ts
