Friday, April 07, 2006

Replace every instance of the text "Foo" and "Bar" with "Fox"

$ sed 's/ Foo\| Bar/ Fox/ g' README

Replace every instance of the text "Foo" with "Bar" in README

$ sed 's/ Foo / Bar / g' README

Output all the text from file Foo.txt except between “Chapter 2” and "Chapter 5"

$ sed '/Chapter 3/,/ Chapter 4/ p' book-draft

Output all the text from file Foo.txt between “Chapter 2” and "Chapter 5"

$ sed -n '/Chapter 2/,/ Chapter 5/ p' Foo.txt

Output lines 80 to 88 of file README

$ sed '80,88! d' README

Output line 88 of file README

$ sed '88! d' README