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
Now, the result will be printed on the screen, and...