Results 1 to 4 of 4
Hi
I am trying to search and replace a multi line pattern in a php file using awk.
The pattern starts with
<div id="navbar">
and ends with
</div>
and spans ...
- 05-01-2011 #1Just Joined!
- Join Date
- Nov 2010
- Posts
- 15
awk multiple line search and replace
Hi
I am trying to search and replace a multi line pattern in a php file using awk.
The pattern starts with
<div id="navbar">
and ends with
</div>
and spans over an unknown number of lines.
I need the command to be a one liner.
I use the "record separator" like this :
but it deletes all theCode:awk -v RS="</div>" -v FILENEW="nouveau.php" '{gsub(/<div\ id\=\"navbar\">.*$/,"<?php include(\"menu.php\"); ?>",$0); print $0 "</div>">FILENEW; system("mv " FILENEW " " FILENAME)}' myfile.php
</div>
in the file.
How can I avoid this?
ThanksLast edited by louisJ; 05-01-2011 at 06:05 PM.
- 05-01-2011 #2Code:
awk '/<div id="navbar">/,/<\/div>/ { next } 1' "$file"
- 05-02-2011 #3
Or use an xsl transformation, which I regard as the preferred way to proces xml documents. OTOH awk is good with data files where the data is structured vertically (in lines).
- 05-02-2011 #4Just Joined!
- Join Date
- Nov 2010
- Posts
- 15
Thanks.
This thread is being answered on unix.com
with the thread name: awk multiple-line search and replace one-liner


Reply With Quote