sed search and replace question
I want to search for a pattern across two consecutive lines and use part of that pattern to change part of the second line. I haven't been able to find anything about sed that would show me how to do it.
Everything I have found shows how to merge lines and add new blank lines but nothing shows how to do what I want. I can do this all day long in Vim but I want to do it in the bash shell using sed or sed & awk or something else because I have several dozen files to do this on and opening them in Vim is painfully slow. This single line below will find a pattern across two consecutive lines then put back everything one the first line and the second line with some added content. Code:
s_^\([ </p>]*<h2 id="\)\(b0[0-9][0-9]c[0-1][0-9][0-9]\)\(" class="chapter">[0-9]\+</h |
Give us an example of the two consecutive lines _and_ an example of the result you want to accomplish.
|
What I have
<h2 id="b001c001" class="chapter">1</h2><p> I What I want <h2 id="b001c001" class="chapter">1</h2><p> <span id="b001c001v001" class="verse">1</span> I The second line has more than just the one capital letter but the rest of the line isn't touched or changed. Like I said in my OP this works all day long in Vim very well. I would rather run it from the cli doing about 1200 pairs of lines within several dozen files. |
here is a tutorial about multi line regex and sed: http://www.grymoire.com/Unix/Sed.html#uh-51
otherwise perl is suggested, probably it handles this case better this will do something similar (what you wish), but I'm not really sure: Code:
perl -we ' |
All times are GMT -5. The time now is 03:15 AM. |