Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 6. Manipulating Files > Making global changes with sed

Making global changes with sed

Another handy command you can use is sed, which lets you make multiple changes to files, without ever opening an editor. For example, as a new Webmaster, you might use sed to change all occurrences of the previous Webmaster's e-mail address to your own, as shown in our example below. As we'll show in this section, you can use sed to make global changes within documents.

To make global changes with sed:

  • sed /oldaddr@raycomm.com 
    → /newaddr@raycomm.com/g address.htm 
    → > address.htm

    Type sed, followed by

    • /the text you want to replace (/oldaddr@raycomm.com)

    • A slash (/)

    • The replacement text (newaddr@raycomm.com)

    • Another /

    • g, which tells UNIX to apply the change globally. (If you omit the g, only the first occurrence on each line will be changed.)

    • The name of the file in which the changes should be made (address.htm).

    You can redirect the output to the same file name (as we did here; see Code Listing 6.10), redirect it to a new one, or pipe it to another command entirely.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial