Previous Section  < Day Day Up >  Next Section

5.5. Addressing

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.

    Previous Section  < Day Day Up >  Next Section