From rouben@sun2.math.umbc.edu Mon Apr 20 20:45:33 1998 Path: fu-berlin.de!feeder.qis.net!news.umbc.edu!not-for-mail From: rouben@sun2.math.umbc.edu (Rouben Rostamian) Newsgroups: alt.unix.wizards,comp.unix.aix,comp.unix.admin,comp.unix.misc,comp.editors Subject: Re: Can sed do this?? Followup-To: comp.editors Date: 11 Apr 1998 13:09:28 -0400 Organization: University of Maryland Baltimore County Lines: 49 Distribution: inet Message-ID: <6go848$4jd@sun2.math.umbc.edu> References: <352EFB3C.A5B95A41@nettally.com> NNTP-Posting-Host: sun2.math.umbc.edu Xref: fu-berlin.de alt.unix.wizards:13014 comp.unix.aix:133213 comp.unix.admin:79040 comp.unix.misc:39056 comp.editors:30780 In article <352EFB3C.A5B95A41@nettally.com>, Bob Tortajada wrote: >I need to edit a file from a shell script and don't know how to do one >thing. Specifically, the file I need to edit is /etc/filesystems so here >is an example > >/mnt/fs1: > dev = /dev/lv1 > vfs = jfs > log = /dev/log1 > >/mnt/fs2: > dev = /dev/lv2old > vfs = jfs > log = /dev/log1 >In the above example, we only want to change the entry's with old in >their name, but what we want to change it the log entry two lines down. >What I want to do is basically search for old then search for log and >change log1 to log2. As far as I can see, sed doesn't work that way. Is >this possible with sed? (Note that I have changed the Followup-To: line) Make a file, say script.sed, with the following contents: ------------------------------- :b1 /old/{ :b2 n /log/{ s/log1/log2/ n bb1 } bb2 } ------------------------------- Then do: sed -f script.sed infile > outfile You may want to strengthen the regexps /old/ and /log/ to make the script fool-proof. -- Rouben Rostamian