Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Working with Linux ??? Quick Hacks for the Command Line

You're reading from   Working with Linux ??? Quick Hacks for the Command Line Command line power like you've never seen

Arrow left icon
Product type Paperback
Published in May 2017
Publisher Packt
ISBN-13 9781787129184
Length 222 pages
Edition 1st Edition
Tools
Concepts
Arrow right icon
Authors (2):
Arrow left icon
Bogdan Vaida Bogdan Vaida
Author Profile Icon Bogdan Vaida
Bogdan Vaida
Petru I»ôfan Petru I»ôfan
Author Profile Icon Petru I»ôfan
Petru I»ôfan
Arrow right icon
View More author details
Toc

Sed – one-liner productivity treasure

If a picture is worth 1000 words, then sed one liners are definitely worth a thousand lines of code! One of the most feared commands in the Linux CLI is, you guessed it, sed! It's been feared by programmers and sysadmins everywhere, because of it's cryptic usage, but it can serve as a very powerful tool for quickly editing large amounts of data.

We have created five files to help demonstrate the power of this awesome tool. The first one is a simple file containing the humble line of text: Orange is the new black. Let's start by creating a simple sed command to replace the word black with white.

The first argument of sed is the replace command. It's divided into 3 parts by 3 /. The first part is s for substitute, the second part is the word to be replaced, black, in our case, and the third part is the replacement word, white.

The second argument is the input, in our case, a file:

sed "s/black/white/" 1.txt
Sed – one-liner productivity treasure

Now, the result...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime