Reputation: 186562
Here is the input I have and the output I want:
Input:
<hr />
(newline)
( carriage return)
(tabs, spaces)<div id="sidebar">
Output:
</div>
<hr />
(newline)
( carriage return)
(tabs, spaces)<div id="sidebar">
This doesn't seem to match it:
sed -i 's/<hr \/>[[:space:]]*<div id="sidebar">/<\/div><hr \/><div id="sidebar">/g' file.txt
Hrm?
Upvotes: 1
Views: 299
Reputation: 342333
then you don't really need to do substitution. just check for the "<hr >"
line, then print "</div>"
before it.
awk '/<hr \/>/{ print "</div>" } 1 ' file
Upvotes: 0
Reputation: 124287
I don't think you can really do this with sed
, because I don't know of any way to convince it to operate on multiple lines at once. It really wants to operate on one line at a time. You can do it reasonably easily with Perl, though:
perl -pi -e 's/<hr \/>\s*<div id="sidebar">/<\/div><hr \/><div id="sidebar">/gs;' -e 'BEGIN { $/ = ""; }' file.txt
Upvotes: 2