Newsgroups: comp.unix.shell Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!think.com!linus!progress!root From: root@progress.COM (Root of all Evil) Subject: search and replace string from a script Message-ID: <1991Apr23.180034.7349@progress.com> Summary: replacing nth pattern in file? Keywords: search replace script Sender: usenet@progress.com (Mr. Usenet) Nntp-Posting-Host: pscdev2 Organization: Progress Software Corp. Date: Tue, 23 Apr 1991 18:00:34 GMT Lines: 26 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@progress.com 5 Oak Park >- Insert funny stuff here -< Bedford, MA 01730 >-Draw amusing symbols, logo's-< USA >- or characters here -<