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.
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityJust add a backslash before the backtick:
grep -Rl "'30" /myDir | xargs sed "s/'30/\`30/g"
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.
tr "'" '`'
instead of sed