5.5. Addressing

 <  Day Day Up  >  

You can use addressing to decide which lines you want to edit. The addresses can be in the form of decimal numbers or regular expressions (also called context addresses), or a combination of both. Without specifying an address, sed processes all lines of the input file.

When an address consists of a number, the number represents a line number. A dollar sign can be used to represent the last line of the input file. If a comma separates two line numbers, the addresses that will be processed are within that range of lines, including the first and last line in the range. The range may be numbers, regular expressions, or a combination of numbers and regular expressions.

Sed commands tell sed what to do with the line: print it, remove it, change it, and so forth.

FORMAT

 sed 'command' filename(s) 

Example 5.4.
 1  sed '1,3d' myfile  2  sed -n '/[Jj]ohn/p' datafile  

EXPLANATION

  1. Lines 1 through 3 of myfile are deleted.

  2. Only lines matching the pattern John or john in myfile are printed.

 <  Day Day Up  >  


UNIX Shells by Example
UNIX Shells by Example (4th Edition)
ISBN: 013147572X
EAN: 2147483647
Year: 2004
Pages: 454
Authors: Ellie Quigley

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net