Skip to content
Prev 163123 / 398500 Next

How to create a string containing '\/' to be used with SED?

Hi guys,
I've been struggling to find a solution to the following issue:
I need to change strings in .ini files that are given in input to a program
whose output is processed by R. The strings to be changed looks like: 
"instance = /home/TSPFiles/TSPLIB/berlin52.tsp" 

I normally use Sed for this kind of things. So, inside R I'd like to write
something like:

 command <- paste("sed -i 's/^instance .*/instance = ", data$instancePath,
                   data$newInstance, "/' ", configurationFile, sep = "")
 system(command)

This will overwrite the line starting with "instance " using "instance =
the_new_instance"
In the example I gave, data$instancePath = /home/TSPFiles/TSPLIB/ and 
data$newInstance = berlin52.tsp

The problem is that I need to pass the above path string to sed in the form:
"\/home\/TSPFiles\/TSPLIB\/" 

However, I couldn't find a way to "create" such a string in R. I tried in
several different ways,
but it always complains saying that '\/' is an unrecognized escape!
 
Any suggestion? 

Thanks!