On Fri, 31 Mar 2006, Steven Heimann wrote:
**1. Scope**
I wrote the following
sed -i.bak "s/^\(\*\*[0-9][. ]\)\*\*\(.*\)$/\1\2**/" *.txt
Unfortunately sed seems to be putting the 2 trailing ** at the beginning
of the replacement line rather than the end of the line and after much
stuffing around I still can't work out what is going wrong.
You don't provide an example of what you mean by this behaviour.
It sounds like your sample ends up as '****1. Scope'. As with everyone
else, I don't see how this would happen.
From your below comment, you have MS style newlines. You can work around
that by making the final '.' match a '[^\r]' instead, and put an optional
carraige return on the end (getting messier):
sed 's/^\(\*\*[0-9][. ]\)\*\*\([^\r]*\)\(\r\?\)$/\1\2**\3/'
(also note that I prefer single quotes :-) )
Or just piping through dos2unix before and then unix2dos after.
If I leave out the $ in the regex to match then I get ^M embedded into
the replacement string i.e "**1. Scope^M**"
I get this behaviour with and without the $.
$ echo -e '**1.** Scope\r' | sed 's/^\(\*\*[0-9][. ]\)\*\*\(.*\)$/\1\2**/' |
cat -A
**1. Scope^M**$
Can anyone see what I am doing wrong?
Apparently sed doesn't treat the carriage return (^M) as part of the end
of line... pattern otherwise looks fine.
Cheers,
- Simon (sed 4.1.2)
Thanks for your help
Steven
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html