Question

When called from the terminal,

sed -i -e 's/^/#\x27 /' file

edits file by inserting #' at the beginning of each line. But I want to do this from within R. First, I note that executing the string

"sed -i -e \'s/^/#\x27 /\' file"

in R returns

"sed -i -e 's/^/#' /' file"

The problem is that the \x27 got interpreted already, so my desired command

system("sed -i -e \'s/^/#\x27 /\' file")

fails with an error message about an unterminated string. How can I pass the sed command to the command line from within R?

Was it helpful?

Solution

That's not what happens with that sed command on my device (a Mac). I get the same behavior using just sed as I get with doubling the backslash (i.e. escaping the backslash:

system("sed -i -e 's/^/#\\x27 /\' file.txt")

In both cases I see #\x27 in the text.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top