how to insert new line if a line has more than 60 characters

Try:

$ awk '{print $1; for (i=1;i<=length($2);i=i+60) print substr($2,i,60)}' file
>Directory1/file3
CTTSCCCTTTTTSEEEEECGGGSCEEEEECCCSSBCCCSCCCCCTTTCCCCCCCCSCBCC
CCCCCCSCTTSCCCTTTTTSEEEEECGGGSCEEEEECCCSSBCCCSCCCCCTTTCCCCCC
CCSCBCCCCCCCCSCTTSCCCTTTTTSEEEEECGGGSCEEEEECCCSSBCCCSCCCCCTT
TCCCCCCCCSCBCCCCCCCCS
>Directory1/file4
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAA

How it works:

  1. print $1

    This prints the first field on the line.

  2. for (i=1;i<=length($2);i=i+60) print substr($2,i,60)

    For the second field on the line, we print 60 characters at a time until we reach the end of the field.


You can use GNU coreutils fold:

fold -w60 file

Tags:

Linux

Text

Awk

Sed