?
Solved

How do I write this in BASH script? Escape Function for Sed

Posted on 2008-11-14
1
Medium Priority
?
1,183 Views
Last Modified: 2013-12-26
Hi,

I am doing a lot of  find / -name "*" -type f -exec sed -i 's/STRING1/STRING2/' {} \;

But I am going crazy because everytime I need to manually escape chars like / and & in STRING1 and STRING2. Is there a way to write it or perhaps to use a extra function, so I dont have to escape strings like this - > Hosted for free by <a href="http:\/\/www.fleeforum.com" target="_blank">fleeforum.com<\/a> \&copy;  

Thank you.
0
Comment
Question by:Octalys
1 Comment
 
LVL 48

Accepted Solution

by:
Tintin earned 2000 total points
ID: 22965593
sed can use whatever character you like as a delimiter.  By default, most people use a forward slash as it is easier to read.

So if you have

sed -i 's#STRING1#STRING2#

then you don't need to escape any forward slashes, and that will save you most of the extra typing.'
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

750 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question