line 1
line 2\
line\3
When I read the file into a variable, the variable looks like this:
line 1\nline 2\\nline\3
What I want to do is to use regsub to add a space after all backslashes
that appear right before newline characters. I tried this:
regsub -all "\\\n" $text "\ \n" text
..but it added a space in front of every newline, regardless of the
presence of a trailing backslash. Any suggestions?
jase
--
/\ Jase P Wells, Scopus Administrator Email: ja...@altagroup.com
/- \ Alta Business Unit of Cadence Direct: 408.523.8706 ____
/-- \ 555 North Mathilda Avenue Main: 408.733.1595 \ /
/______\ Sunnyvale, California 94086 Fax: 408.523.4601 \/
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
You want: regsub -all "\\\\\n" $text "\\ \n" text
You need the extra escaping of the \ in the reg exp because of the
extra level of special character evaluation by the regexp compiler.
You also need to remember that in the subspec you were just putting
in a space (escaped) instead of the backslash and space.
--
Jeffrey Hobbs jho...@cs.uoregon.edu,@or.cadix.com
Software Engineer, Oregon R&D office: 541.683.7891
CADIX International, Inc. fax: 541.683.8325
URL: http://www.cs.uoregon.edu/~jhobbs/
Am I correct that the output for the above case would end up looking
like this: "line1\nline2\ \nline\3" -- that only one space would be
added in the second line?
If so, try this: regsub -all "\\\\\n" $text "\\\\ \n" bar
What is happening in your original example is that the command line
processing is turning this: "\\\n" into this: "\<nl>". Remember that "\"
is special to regsub too, so the backslash is escapeing the following
newline which gets interpreted as just a newline. You need to make sure
that regsub sees "\\" in order to match a single \. So, to pass \\ to
regub, in order to get past the command line substitution you must use
\\\\. Gross, but that's the way it is.
Put in the simplest terms possible, if a regexp is in quotes, to match
"\" you must use "\\\\".
Does that make sense?
--
Bryan Oakley mailto:oak...@healthcare.com
Software Engineer http://www1.clearlight.com/~oakley/
Healthcare Communications, Inc. http://www.healthcare.com/