LiveFire Labs: Online UNIX Training with Hands-on Internet Lab


"Taking a LiveFire Labs' course is an excellent way to learn Linux/Unix. The lessons are well thought out, the material is explained thoroughly, and you get to perform exercises on a real Linux/Unix box. It was money well spent."

Ray S.
Pembrook Pines, Florida



LiveFire Labs' UNIX and Linux Operating System Fundamentals course was very enjoyable. Although I regularly used UNIX systems for 16 years, I haven't done so since 2000. This course was a great refresher. The exercises were fun and helped me gain a real feel for working with UNIX/Linux OS. Thanks very much!"

Ming Sabourin
Senior Technical Writer
Nuance Communications, Inc.
Montréal, Canada

Read more student testimonials...




Receive UNIX Tips, Tricks, and Shell Scripts by Email







Custom Search



LiveFire Labs' UNIX Tip, Trick, or Shell Script of the Week

A Brief Introduction to sed

Unlike the UNIX editors vi and emacs, sed is a "non-interactive" stream-oriented editor.  This "non-interactive" trait allows you to use sed to automate editing sequences if desired.  The name sed is an abbreviation for stream editor, and the utility derives many of its commands from the ed line-editor (ed was the first UNIX text editor).

The power and usefulness of sed can be seen when the same edit, or a series of edits, has to be performed multiple times in a single file, or one or more times in multiple files.  Imagine having to use vi interactively to make the same changes to 100 different files.

sed commands can be issued on the command line using the following syntax:

sed [-e] 'command1' [-e command2...] [file]

Notice that more than one sed command can be performed by prefacing each command with the "-e" option.  This option is not required if only one command is used.  Specifying a file is optional because sed can take its input from either files or stdin (standard input).

Similar to a UNIX shell script, multiple sed commands may also be stored in a script file.  The "-f" option is used on the command line to access the commands in the script:

sed -f script [file]

The follow text from our home page will be used to demonstrate a frequently-performed sed operation, text substitution (replacement):

LiveFire Labs specializes in providing quality, affordable, and globally
accessible hands-on UNIX training to students who are serious about learning
the UNIX operating system and related technologies. UNIX technologists develop
and support our courses, and each course is designed to take advantage of the
company's innovative hands-on training model.

For this week's examples, this block of text will be stored in a file named LFL.

Consider the following command and its stdout (standard output):

$ sed 's/UNIX/unix/' LFL
LiveFire Labs specializes in providing quality, affordable, and globally
accessible hands-on unix training to students who are serious about learning
the unix operating system and related technologies. UNIX technologists develop
and support our courses, and each course is designed to take advantage of the
company's innovative hands-on training model.

The s command replaces the first occurrence of UNIX on each line in the file with unix.  Adding g to the end of the s command will instruct sed to perform a global substitution (all instances of UNIX will be replaced with unix):

$ sed 's/UNIX/unix/g' LFL
LiveFire Labs specializes in providing quality, affordable, and globally
accessible hands-on unix training to students who are serious about learning
the unix operating system and related technologies. unix technologists develop
and support our courses, and each course is designed to take advantage of the
company's innovative hands-on training model.

This extremely brief introduction to sed does not even begin to scratch the surface on its capabilities, but you should now have a basic understanding of what sed is, how it differs from other UNIX editors, and when it may be appropriate to use the utility for editing text.