Carl Lowenstein wrote:

On 2/11/07, Ralph Shumaker <[EMAIL PROTECTED]> wrote:

I've been having fun, playing with regular expressions in vi. But I'd
like to do more.

How can I do a search that regards line breaks as if they were a space?

If that's not easy, then how can I replace all line breaks with a space
except for line breaks or double line breaks preceding any line that
begins with "^"?

I have a text file that has been line wrapped at about 80 characters.
Each real line begins with the "^". Each wrapped line does not. And
each line that begins with "^" is preceded by a blank line.

Text that I want to search for (or replace) can wrap around these line
breaks, but not around the "^".


You might be better off if you first processed the test file to rejoin
the split lines.


Yeah, I just did that, with pieces provided by you, Stewart, and others.
":%s/\([a-zA-Z0-9,\.:;?!)’-]\)\n\([A-Z^a-z(]\)/\1 \2/cg"
(A week ago, I would have only understood bits and pieces of this formula.) I hit "y" for yes enough times to feel reassured that the formula was working right and then hit "a" for all.

(Please forgive my incorrect terminology:)
: enter command mode
% traverse the entire file from beginning to end
s substitute
/ begin set to search for
\( begin copy function
[ begin single match set
a-z match any character a through z or
A-Z match any character A through Z or
0-9 match any character 0 through 9 or
, match comma or
\. match period or
: match colon or
; match semi-colon or
? match question mark or
! match exclamation point or
) match close parenthesis or
’ match apostrophe or
- match hyphen
] end single match set
\) end copy function
\n match newline only
\( begin second copy function
[ begin single match set
A-Z match any character A through Z or
^ match carret or
a-z match any character a through z or
( match open parenthesis
] close single match set
\) end second copy function
/ end substitution's search set, begin replacement set
\1 \2 replace with paste of 1st and 2nd copy separated by a space
/ end substitution set
c confirm each replacement
g get multiple matches on a single line

And now I don't have to accommodate "\n" in my substitutions.

Now, is there a way to do these kinds of substitutions via a script? In other words, can I create a script file that I can just add new substitution commands, execute the script, and it run anew on the original, each time outputing to an output file?

Basically, I want to figure out as I go, what all substitutions need to be made to the original, but without continuing to change the output, and change the output, and change the output. I don't mind that the script would be repeating what it's already done. But if I add a new substitution command, I want it (and all its predecessors) executed upon the original each time. When I'm done, the script will show exactly what changes were made between the original and the result. (I will continue to test each new substitution within vi before I add it to the script.)

Thanks to all.


--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list

Reply via email to