Using sed to replace a word in a file
Using sed to Replace a word in a file
It’s really pain to replace a 100’s of words from a file manually.
So I needed a command that could do this for me. That’s when I found sed, a stream editor. sed can replace a word or set of words with a different word or set of words.
There’s a couple different ways to use sed. You can have it replace only the first instance of a word in a sentence or you can have it replace the word globally.
To replace only the first instance of a word in a sentence the command looks like this
sed -i ‘s/original_word/new_word/’ file.txt
To change all instances of a word in a file the command is
sed -i 's/original_word/new_word/' file.txt
the “g” at the end tells sed to perform the action globally.
You can also do more than one word, like a phrase. To do this correctly you need to use a “\” backslash before the space. So for example I wanted to replace all instances of “black” with “light blue” in my color.sql This is what the command looked like
sed -i 's/original_word/new_word/' file.txt
That saved me about 5 minutes of editing my color.sql
So there you have it, a very useful time saving command.
Or you can use the Replace button in Gedit which somehow I managed to overlook while trying to figure out a command to do this!
Incredible! This blog looks just like my old one! It’s on a totally different subject but it has pretty much the same layout and design. Outstanding choice of colors!
This piece of writing offers clear idea in support of the new visitors of blogging, that truly how to do blogging.
What’s Going down i am new to this, I stumbled upon this I’ve found It absolutely helpful and it has aided me out loads. I hope to give a contribution & help other customers like its helped me. Good job.
These are really fantastic ideas in on the topic of blogging. You have touched some fastidious things here. Any way keep up wrinting.
Its such as you learn my thoughts! You appear to understand a lot approximately this, such as you wrote the ebook in it or something. I feel that you just could do with a few percent to pressure the message home a bit, but instead of that, that is fantastic blog. An excellent read. I’ll definitely be back.
First off I would like to say excellent blog! I had a quick question which I’d like to ask if you do not mind. I was interested to find out how you center yourself and clear your thoughts prior to writing. I have had a hard time clearing my mind in getting my ideas out. I do enjoy writing but it just seems like the first 10 to 15 minutes are usually lost just trying to figure out how to begin. Any ideas or hints? Thanks!
Excellent pieces. Keep writing such kind of info on your page. Im really impressed by it.
First of all I would like to say excellent blog! I had a quick question that I’d like to ask if you don’t mind. I was curious to find out how you center yourself and clear your thoughts prior to writing. I have had a tough time clearing my mind in getting my thoughts out. I truly do take pleasure in writing however it just seems like the first 10 to 15 minutes are lost just trying to figure out how to begin. Any ideas or tips? Cheers!
Thanks for every other informative website. The place else may I am getting that kind of info written in such an ideal manner? I’ve a project that I’m simply now running on, and I’ve been at the glance out for such information.
Usually I do not learn post on blogs, but I wish to say that this write-up very compelled me to try and do it! Your writing taste has been surprised me. Thanks, quite great article.|
I’ve been exploring for a little bit for any high quality articles or weblog posts on this sort of space . Exploring in Yahoo I at last stumbled upon this site. Studying this information So i am glad to exhibit that I have an incredibly excellent uncanny feeling I discovered just what I needed. I most indisputably will make sure to do not omit this web site and give it a look regularly.
I’m curious to find out what blog system you have been using? I’m experiencing some minor security issues with my latest blog and I would like to find something more safe. Do you have any suggestions?