cat $* | sed 's/\t/ /g' | awk ' BEGIN { N=30; for(i=1;i<=N;i++)blanks=blanks " "; }
{
if((n=length($0)) <= N)
print
else
{
nFolds=int(n/N);
nResidue=n%N;
j=1;
for(i=1;i<=nFolds;i++)
{
printf "%s\\\n" ,substr($0,j,N);
j+=N;
}
printf "%s%s\n" , substr(blanks,1,N-nResidue), substr($0,n-nResidue);
}
}'
OUTPUT:-
#!/bin/bash
#root@slack-linunx:~/scripts# ./foldLines.sh testFile
#AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\
#AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\
# AAAAAAAAAAAAAAAA
#AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\
#AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\
# AAAAAAA
#AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\
# AAAAAAAAAAAAAAAAAAAAAAA
#root@slack-linunx:~/scripts#
{
if((n=length($0)) <= N)
else
{
nFolds=int(n/N);
nResidue=n%N;
j=1;
for(i=1;i<=nFolds;i++)
{
printf "%s\\\n" ,substr($0,j,N);
j+=N;
}
printf "%s%s\n" , substr(blanks,1,N-nResidue), substr($0,n-nResidue);
}
}'
OUTPUT:-
#!/bin/bash
#root@slack-linunx:~/scripts# ./foldLines.sh testFile
#AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\
#AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\
# AAAAAAAAAAAAAAAA
#AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\
#AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\
# AAAAAAA
#AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\
# AAAAAAAAAAAAAAAAAAAAAAA
#root@slack-linunx:~/scripts#
0 comments:
Post a Comment