The awk program that i will include below is an implmentation of the unix fold command.The program currently folds lines of input that are more than N characters.I want to modify it so that it will fold lines only on blanks(so that it won't split words when folding the input lines).So here's the unmodified source:
code:
sed 's/<tab>/ /g' $* | #substitute a tab for 8 spaces
awk '
BEGIN {
N = 80
for(i=1;i<=N; i++)
blanks = blanks " "
}
{ if((n = length($0)) <= N)
print
else {
for(i = 1; n > N; n -= N) {
printf "%s\\\n", substr($0, i, N)
i += N;
}
printf "%s%s\n", substr(blanks, 1, N-n), substr($0, i)
}
} '
So please could someone kindly type a modified version that will not split words when folding or give me some suggestions.Oh and no this is not part of a college course etc.Thankx in advance
code:
sed 's/<tab>/ /g' $* | #substitute a tab for 8 spaces
awk '
BEGIN {
N = 80
for(i=1;i<=N; i++)
blanks = blanks " "
}
{ if((n = length($0)) <= N)
else {
for(i = 1; n > N; n -= N) {
printf "%s\\\n", substr($0, i, N)
i += N;
}
printf "%s%s\n", substr(blanks, 1, N-n), substr($0, i)
}
} '
So please could someone kindly type a modified version that will not split words when folding or give me some suggestions.Oh and no this is not part of a college course etc.Thankx in advance