Stanford University School of Earth Science
 
Home
News
New Users
Policies
Network File Server
Web Server
Get Help
Net Connections
Your Macintosh
Your Windows PC
Your Unix/Linux System
Other School Resources
Using Unix
   Overview
   Documentation
   Accounts
   Using the Shell
   Using X-Windows
   File Manipulation
   Net Commands
   Editing Text
   Formatting Text
   Printing
   Filters & Utilities
   Programming

sed examples

Last revision August 6, 2004

Table of Contents:

  1. Forms of addresses in sed commands
  2. Functions in a sed command
  3. sed examples
 

Remove trailing blanks or tabs at the end of any line:

    sed -e 's/[ ^I]*$//' input > output

(here, the ^I means the TAB character, normally obtained by pressing the TAB key, although you can also press CTRL-I).

Add a newline character after each input line to create "double spaced" output:

    sed -f 'addnl.sed' input > output

Here, the sed commands are more complicated and stored in a script file addnl.sed, whose contents are:
      a\
(That is, "a\" on the first line, followed by a blank line).

Delete lines in a range. This example deletes all the message lines in a Microprobe output file up to the start of the first data output lines (denoted by a line starting with "Pt #")
      sed -e '1,/^Pt #/d' 1174.prb > 1174.data

 


Comments?

Stanford University    |