Pattern Matching Multiple Lines with SED and AWK

Pattern Matching Multiple Lines with SED and AWK

Post by Chris Gra » Mon, 05 Oct 1998 04:00:00



Okay, so I've read all of the guides on using SED and AWK and have been
successful in writing scripts to replace text in a line in multiple files.
However, I have had no luck finding out how to pattern match on mutliple
lines and then make a change.  Here's my problem, I need to add

    <!--

before the following lines of code:

    <CENTER><TABLE BORDER=0><TR><TH>
    <div align="center"><center>
    <table border="2" cellpadding="0" cellspacing="0">
    <tr>
    <td><CENTER>

and add

    -->

after:

    </td>
    </tr>
    </table>
    </center></div>
    </TH></TR></TABLE></CENTER>
    <P>

I've got this in hundreds of files and really don't want to edit each one by
hand.  So, if you know of a solution please let me know.  Also, I've read
through about 12 guides to SED and AWK and haven't found anything dealing
with pattern matching MULTIPLE lines.  Is there some escape character that
SED and AWK use to recognize a new line?

chris...

 
 
 

Pattern Matching Multiple Lines with SED and AWK

Post by Chris Gra » Mon, 05 Oct 1998 04:00:00


sorry, wrong group.  meant comp.unix.questions.

 
 
 

Pattern Matching Multiple Lines with SED and AWK

Post by Mike Mill » Sat, 10 Oct 1998 04:00:00



>Okay, so I've read all of the guides on using SED and AWK and have been
>successful in writing scripts to replace text in a line in multiple files.
>However, I have had no luck finding out how to pattern match on mutliple
>lines and then make a change.  Here's my problem, I need to add

>chris...

There's a script on pages 64 & 65 in the Sed and Awk book that will do
what you want. The idea is to use more than one line to do the
matching. Use one line for each pattern if needed.
Mike
 
 
 

Pattern Matching Multiple Lines with SED and AWK

Post by Mike Mill » Sat, 10 Oct 1998 04:00:00



>Okay, so I've read all of the guides on using SED and AWK and have been
>successful in writing scripts to replace text in a line in multiple files.
>However, I have had no luck finding out how to pattern match on mutliple
>lines and then make a change.  Here's my problem, I need to add

>chris...

There's a script on pages 64 & 65 in the Sed and Awk book that will do
what you want. The idea is to use more than one line to do the
matching. Use one line for each pattern if needed.
Mike
 
 
 

1. Matching Line After Pattern (Pattern Occurs Multiple Times)

Note: Cross Post from comp.unix.misc.

Hello, I have a sorted list that contains dates:

1/1/2005
1/1/2005
1/8/2005
1/10/2005
1/10/2005
1/10/2005
1/15/2005
1/21/2005
1/21/2005

I need a one liner that matches the line after the last occurance of
the pattern to the end of the file. So in the example if the regex was
1\/10\/2005, it would match after the 3rd occurence of 1/10/2005; the
output would contain 3 lines starting at 1/15/2005.

I have tried: sed '1,'1\/10\/2005'/d, but that prints the 2nd occurance
to the end of the file. I have also looked around the newsgroups and
have seen similar functionality in AWK, GREP and PERL, but I have not
stumbled into the solution.

I would appreciate it if you could point me in the right direction.

TIA

2. PPP, apppls, modem hangups

3. inserting lines before and after lines with matching pattern using sed?

4. SOl 8 x86 NFS starting problem....

5. How to replace a whole line (matching a pattern) in a text filke with SED ?

6. Miro 12SD with S3-Trio

7. Sed to match multiple patterns

8. Setting up ttyS0 (com1) for APC SmartUPS

9. Better pattern match for multiple occurances in sed?

10. matching pattern over multiple lines

11. using sed/awk to output lines following a pattern

12. Matching a pattern in a file and inserting variable string above the line matched?

13. Pattern matching and extracting the data which matches the pattern