#!/bin/bash awk -F "" '{ f=NF%3 for (i=1;i<=NF;i++){ printf $i if((i-f)%3==0 && i!=NF) printf "," } print "" }' nowcoder.txt