Richard Lewis <richardlewis@fastmail.co.uk> wrote:
Hello ALUG,
I wonder if anyone can help with a regular expression (for text wrapping)?
I need to match all the characters from either the beginning of the line or the last match (in global mode) up to the last space before the Xth character.
I can do the first space after the Xth character:
$ echo "A string with quite a lot of words and spaces in it." | sed "s/\(.\{,X\}\) /\1\n/g"
Hows about forgetting the regexp and using the right tool for the job? $ echo "A string with quite a lot of words and spaces in it." | fmt -w 22 A string with quite a lot of words and spaces in it. $ $ echo "A string with quite a lot of words and spaces in it." | fmt -w 44 A string with quite a lot of words and spaces in it. $ fmt is nice and will do what you want. On debian systems it's in the coreutils package, so should be on every debian system going. Thanks, -- Brett Parker web: http://www.sommitrealweird.co.uk/ email: iDunno@sommitrealweird.co.uk