Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

spliting a line after a set character length 1

Status
Not open for further replies.

wnoland

Technical User
Aug 24, 2001
2
US
I have a file that has line characters lengths of varable sizes. What I need to do is if a line has more than 240 characters. Take that line split it at the next comma and take the rest of the line and make a newline,and if that line exceeds 240 characters split it in the same manner.

Thanks wnoland

 
This should do it.

{
if (length > 240) {
for (i=240;i<length-1;i++) {
if (substr($0,i,1) == &quot;,&quot;) {
print substr($0,1,i)
print substr($0,i+1)
break
}
}
if (i>length-2) print
}
else
print
}

Hope this helps.

CaKiwi

&quot;Cheer up&quot; they said, &quot;Things could be worse&quot;. So we did and they are.
 
This is slightlty better.

{
if (length > 240) {
for (i=240;i<length;i++) {
if (substr($0,i,1) == &quot;,&quot;) {
print substr($0,1,i)
print substr($0,i+1)
next
}
}
print
}
else
print
}

CaKiwi
 
Thank ,CaKiwi
This worked the way I wanted it to.

wnoland
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top