Skip to content
Advertisement

Using linux system commands in R to remove special characters

I’m trying to clean files using linux system commands in R

I would like to use a command that removes special characters apart from the file separator (pipe delimited)

In the example below it’s the slashes and additional quotation marks that I’m trying to get rid of

JavaScript

I’ve used the command below, but it doesn’t appear to be removing the characters.

sed ‘s/”?//g’ input_file.txt > output_file.txt;

Advertisement

Answer

If the file x.txt looks like this

JavaScript

Then you can use sed in system(), like this

JavaScript

You can write that to file. Or if you want to return an R vector, add intern = TRUE to the call

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement