Reader small image

You're reading from  Linux Command Line and Shell Scripting Bible - Third Edition

Product typeBook
Published inJan 2015
PublisherWiley
ISBN-139781118983843
Edition3rd Edition
Tools
Right arrow
Authors (2):
Richard Blum
Richard Blum
author image
Richard Blum

Richard Blum has more than 25 years as a network and systems administrator, currently managing Microsoft, Unix, Linux, and Novell servers for a network with more than 3,500 users. He has developed online programming and Linux courses that he teaches to students worldwide.
Read more about Richard Blum

Christine Bresnahan
Christine Bresnahan
author image
Christine Bresnahan

Christine Bresnahan has worked in the IT industry for more than 30 years and is currently an adjunct professor of Python programming and Linux system administration classes at Ivy Tech Community College in Indianapolis. She is the co-author of Linux Bible, Eighth Edition, and Linux Command Line and Shell Scripting Bible.
Read more about Christine Bresnahan

View More author details
Right arrow

Creating sed Utilities

As you've seen in the short examples presented so far in this chapter, you can do lots of cool data-formatting things with the sed editor. This section shows a few handy well-known sed editor scripts for performing common data-handling functions.

Spacing with double lines

To start things off, look at a simple sed script to insert a blank line between lines in a text file:

$ sed 'G' data2.txt
This is the header line.
This is the first data line.
This is the second data line.
This is the last line.
$

That was pretty simple! The key to this trick is the default value of the hold space. Remember that the G command simply appends the contents of the hold space to the current pattern space contents. When you start the sed editor, the hold space contains an empty line. By appending that to an existing line, you create a blank line after the existing line.

You may have noticed that this script also adds a blank line to the last line in the data stream, producing...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Linux Command Line and Shell Scripting Bible - Third Edition
Published in: Jan 2015Publisher: WileyISBN-13: 9781118983843

Authors (2)

author image
Richard Blum

Richard Blum has more than 25 years as a network and systems administrator, currently managing Microsoft, Unix, Linux, and Novell servers for a network with more than 3,500 users. He has developed online programming and Linux courses that he teaches to students worldwide.
Read more about Richard Blum

author image
Christine Bresnahan

Christine Bresnahan has worked in the IT industry for more than 30 years and is currently an adjunct professor of Python programming and Linux system administration classes at Ivy Tech Community College in Indianapolis. She is the co-author of Linux Bible, Eighth Edition, and Linux Command Line and Shell Scripting Bible.
Read more about Christine Bresnahan