$ cat split.sh #!/bin/bash -x <input.txt pr -3tas, <input.txt paste -d, - - - <input.txt awk 'ORS=NR%3?",":"\n"' <input.txt perl -pe'$.%3&&s/\n/,/' <input.txt split -l3 --filter=paste\ -sd, <input.txt perl -l0pe '$_.=$.%3?",":"\n"' $ ./split.sh + pr -3tas, A,B,C D,E,F + paste -d, - - - A,B,C D,E,F + awk 'ORS=NR%3?",":"\n"' A,B,C D,E,F + perl '-pe$.%3&&s/\n/,/' A,B,C D,E,F + split -l3 '--filter=pas