001、每行输出为4个碱基
[root@pc1 test]# ls test.fa [root@pc1 test]# cat test.fa >chr1 aatt cctt >chr2 ttgg aacc >chr3 TTCCGG [root@pc1 test]# awk '{if($0 ~ /^>/) {print $0} else {printf("%s", $0)}}' test.fa | sed '2, $ s/>/\n>/' | sed '$ s/$/\n/' | awk -F "" '{if($0 ~ /^>/) {print $0} else {for(i = 1; i <= NF; i++){if(i % 4 == 0) {print $i} else {printf("%s", $i)}}if((i - 1) % 4 != 0){printf("\n")} }}' >chr1 aatt cctt >chr2 ttgg aacc >chr3 TTCC GG
002、每行输出为5个碱基
[root@pc1 test]# ls test.fa [root@pc1 test]# cat test.fa >chr1 aatt cctt >chr2 ttgg aacc >chr3 TTCCGG [root@pc1 test]# awk '{if($0 ~ /^>/) {print $0} else {printf("%s", $0)}}' test.fa | sed '2, $ s/>/\n>/' | sed '$ s/$/\n/' | awk -F "" '{if($0 ~ /^>/) {print $0} else {for(i = 1; i <= NF; i++){if(i % 5 == 0) {print $i} else {printf("%s", $i)}}if((i - 1) % 5 != 0){printf("\n")} }}' >chr1 aattc ctt >chr2 ttgga acc >chr3 TTCCG G