AWK Substring without cutting off word

Can someone help me to make this code without cutting off words ni the string?

awk '{for(i=1;i<length;i+=100) print substr($0,i,100)}'

Thank you!

An alternative:

awk '{gsub(/.{100}/,"&^");n=split($0,a,"^");for(i=1;i<=n;i++) print a}' inputfile

Assuming that "^" character does not appear in the input records.

1 Like

48.being used as a therapy,� she says. resting thro
50.ugh although far-fetched, that in the future we co
48.uld think of cancer being used as a therapy,� sh
50.e says. treatment, Jayant believed that her mind a
49.nd spirit needed healing in addition to her body.

still cut the words... any other ideas why ?
thank you! :slight_smile:

If that's what you want, why not use the fold command? fold -w 100 -s

1 Like

wow this is great command!!!
Thank you!!!!!!