0

I need to replace '30 by `30 in a bunch of files. The following does not work:

grep -Rl "'30"  /myDir | xargs  sed -i "s/'30/`30/g"

How do I fix it?

I am on a Fedora 26 machine.

4
  • What output are you trying to achieve? You might try tr "'" '`' instead of sed Commented Sep 12, 2018 at 15:28
  • I need to replace '30 by `30 in a bunch of tex files.
    – mario
    Commented Sep 12, 2018 at 15:34
  • 2
    That's the kind of detail that needs to be specified in the question. Commented Sep 12, 2018 at 15:54
  • Ok, but actually, that line just does not produce an output. That was the issue.
    – mario
    Commented Sep 12, 2018 at 16:22

2 Answers 2

3

Just add a backslash before the backtick:

grep -Rl "'30" /myDir | xargs  sed  "s/'30/\`30/g"
1
  • 1
    the OP had sed -i...
    – Jeff Schaller
    Commented Sep 12, 2018 at 15:18
0
find /myDir -maxdepth 1 -type f -exec grep -q \'30 {} \; -exec sed -i -e y/\'/\`/ {} +

Here you allow find to filter the files, in the directory /myDir, carrying the string ,'30, and pass only those, in a bunch, to sed, which'll do an in-place editing-i` on them.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .