Sed - A stream editor

sed - A stream editor

Introduction

 * A stream editor reading from a file or standard input
 * Compact programming language; main power is regex; line-oriented
 * Text replacement / substitution

Syntax
sed [options] {sed-commands} {input-file} And here is the more specific/most used format (Addresses) sed '/PATTERN/commands' file

Options

 * -r: enables extended regex
 * -e: enables more than one instruction
 * -i: edit in-place (directly to file)
 * -i.bak: backup original file with .bak extension
 * -n: no print

Pattern flags

 * g: global
 * I: ignore case
 * p: print (duplicate lines without -n used in options)

Delete text from file (d command)
Delete lines starting with "sometext"

sed -ri '/^sometext.*/d' file Delete blank lines sed '/^$/d' file

Replacement (s/.../.../ command)
Syntax 's/regexp/replacement/flags' Remembering patterns with \(, \) and \1 sed -i.bak 's/includes\/\(\w*\).shtml/includes\/\1-local.shtml/' local/*.html Add some characters to the pattern found (&) sed 's/[a-z]*/(&)/' new