GNU sed: Stream EDitor

sed (stream editor) is a Unix utility that parses and transforms text, using a simple, compact programming language.

Brief Introduction

sed (stream editor) is a Unix utility that parses and transforms text, using a simple, compact programming language. sed was developed from 1973 to 1974 by Lee E. McMahon of Bell Labs, and is available today for most operating systems. sed was based on the scripting features of the interactive editor ed (“editor”, 1971) and the earlier qed (“quick editor”, 1965–66). sed was one of the earliest tools to support regular expressions, and remains in use for text processing, most notably with the substitution command. Other options for doing “stream editing” include AWK and Perl. This article records my understanding of sed.

Mind Map of GNU sed

GNU sed Mind Map

Often Used sed commands

# Remove tail spaces from source file
$ sed -i.org 's/[[:blank:]]*$//g' file.c

# Replace TAB with four spaces
$ sed -i.org 's/\t/    /g' file.c

# Replace TAB with four spaces & Remove tail spaces from source file
$ sed -i 's/\t/    /g;s/[[:blank:]]*$//g' file.c

References