On Tue, 15 Feb 2005 14:00:03 +0000, "MJ Ray" mjr@dsl.pipex.com said:
Richard Lewis wrote:
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"
Doesn't that do the last space before the (X+1)th character? I tested it a bit and it seems to. All you need to do is change the space to ( |$) so you don't always split the last word off, I think.
Yes, that seems to be it. Thanks.
On Tue, 15 Feb 2005 14:06:13 +0000, "Brett Parker" iDunno@sommitrealweird.co.uk said:
Hows about forgetting the regexp and using the right tool for the job?
Oh, yes. I should have said: I was only using sed to work out the regex, I need it for an XSLT transformation so unfortunately I don't have the luxury of neat little UNIX tools :-(
Cheers, Richard