|
From: | Clarke Echols |
Subject: | Re: [Groff] Line continuation |
Date: | Sun, 26 Oct 2008 21:49:49 -0600 |
User-agent: | Thunderbird 2.0.0.17 (X11/20080925) |
I wrote an extensive tutorial on sed back about 1987 or so. It's part of HP's HP-UX User Guide series: "Text Editors and Processors". I don't know if you can get your hands on it or not. I based it on the sed standards-conformance tests that were run before the software could be shipped, plus other explanatory stuff. The thing that confuses people about sed is the concept of "pattern space". ^ is the start, and $ is the end, but you can have multiple lines in the space at the same time, with each adjacent pair separated by a newline (represented as \n in substitutions and pattern searches). It's a very powerful program -- especially when run from inside vi (vim) and vi is run non-interactively from a shell script by redirecting input from a command file that ends with "ZZ" or ":wq" on the last line in the file. I overhauled the entire HP-UX Reference (manpages) in a few minutes that way. Took about 3 hours to write and debug the code, but the job ran in less than 5 minutes on a 30-MHz processor. It would be interesting to see how long it would take on a 2-Ghz machine. :-) I converted all in-line coding to macros; i.e., \fB became .B, etc. and I completely changed the typography conventions from AT&T to current industry practice, and got rid of font inconsistencies too. Powerful stuff... Clarke Miklos Somogyi wrote:
Keith, Ralph & Werner,Thank you all for your suggestions. I think that the .nop thing is very ingenious but perhapsa preprocessor that needs to be done only once is the the better way to go.Folks, I've tried your sed things but either my sed does not work (like eqn) or some special charactersdon't come through properly in Mail.I know that sed is a very good thing but I can't get into it. At my age it is better to stick to what I know. And I can do the thing in Perl easily, perhaps not so neatly. And Perl works well under Mac OS 10.5.5.Once again: thank you folks for your kind help, Miklos On 27/10/2008, at 00:17 AM, Keith Marshall wrote:On Sunday 26 October 2008 11:27:38 Ralph Corderoy wrote:To change the sed script to treat a backslash at the end of the line as the continuation marker, you just need to be aware that it needs escaping with another, like Perl. sed ':l;/\\$/{N;s/\\\n *//;b l}'I too would choose sed, but do be aware of a possible pitfall in the above: POSIX demands that the closing brace of a command group be separated from the preceding command, by a newline. Recent versions of GNU sed relax this requirement, and accept the above; some earlier versions may choke on it, but accept sed ':l;/\\$/{N;s/\\\n *//;b l;}' (note the additional semicolon). For strict POSIX conformance, it should be written as sed -e':l;/\\$/{N;s/\\\n *//;b l' -e'}' or sed ':l;/\\$/{N;s/\\\n *//;b l }' (spanning two lines, with a newline within the quoted expression). Regards, Keith.
[Prev in Thread] | Current Thread | [Next in Thread] |