search and replace string from a script

Root of all Evil root at progress.COM
Wed Apr 24 04:00:34 AEST 1991


Is there any way within ex (or some other text processing utility) to
access the nth occurrence of a pattern?  What I'd like to do is search
a file for the nth occurrence of a pattern and then change that pattern
but no others.  I've tried using ex:

ex -s FILE << QUIT
/STRING1/n s/STRING1/STRING2/
wq!
QUIT

but this only places me n lines after the first occurrence of STRING1.
Any ideas?  I'd like to avoid writing to a temporary file.

Thanks...

   Rich

P.S.  I use the Bourne shell.

------------------------------------------------------------------------------
Rich Lenihan                 UUCP: mit-eddie!progress!rich
Progress Software Corp.      Internet: rich at progress.com
5 Oak Park                   >-   Insert funny stuff here  -<
Bedford, MA  01730           >-Draw amusing symbols, logo's-<
USA                          >-     or characters here     -<



More information about the Comp.unix.shell mailing list