4.4. Addressing

You can use addressing to decide which lines you want to edit. The addresses can be in the form of numbers or regular expressions, 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 4.2.
1 % sed '1, 3d' myfile

2 % sed -n  '/[Jj]ohn/p' datafile
				

Explanation

  1. All lines of myfile are printed, except lines 1, 2, and 3 or delete lines 1, 2, and 3.

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

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.77.158