0

How can I do search and replace in a file with the sed command, since I'm currently getting an error.

$command = "sed -i \"y/\xE1\xE9\xED\xF3\xFA\xF1\xC1\xC9\xCD\xD3\xDA\xD1/aeiounAEIOUN/\" file.txt";

exec($command);

I have a .php file from which I execute the previously mentioned command where I intend to eliminate special characters from a .txt file but when doing php script.php I get that error:

sed: -e expression #1, char 1: unknown command: `"'

Suggestions?

  • 4
    Have you tried running that command manually? What makes you think that this is in any way related to PHP? – Nico Haase Apr 08 '19 at 17:12
  • 2
    Is this what you expected? https://3v4l.org/ZE9OX Try with single quotes. – AbraCadaver Apr 08 '19 at 17:18
  • already try single and double quotes. What I intend is to execute the following command: **sed -i 'and / áÁààããââÉÉÉÊÊÍÍóÓõÕôÔúÚñÑçÇ / aAaAaAaAeEeEiIoOoOoOuUnNcC /'** file but from php. – Joel Muñoz Moran Apr 08 '19 at 18:09
  • 1
    A simple `echo $command` would give you an idea what it's trying to do. You're aware that `\xE1` is going to get interpreted by PHP and not sed, right? Also, this is classic X/Y problem. https://stackoverflow.com/questions/1017599/how-do-i-remove-accents-from-characters-in-a-php-string – miken32 Apr 08 '19 at 19:04
  • And finally, why would you want to remove accents? I don't know a lot of Spanish but I know the difference between año and ano. – miken32 Apr 08 '19 at 19:05

0 Answers0