I have a file where the text might exceed 80 characters. I want to have the maximum text lengths to be 80, and cut text from a space.
I written an awk script below but does not seem to work very well
{
gsub("\t"," ")
$0 = line $0
while (length <= WIDTH) {
line = $0
more = getline
gsub("\t"," ")
if (more)
$0 = line " " $0
else
$0 = line
break
}
while (length >= WIDTH) {
print substr($0,1,WIDTH)
$0 = substr($0,WIDTH+1)
}
line = $0 " "
}
END { print }