Remove backquotes from file

Hello,

I have a few thousand files that contain backquotes (`) which were a typo in the program. Now I only want to delete these backquotes from these files.

In these cases I normally use the sed command in a script, but I can't seem to get sed to remove the backquotes. I tried several possibilities:

sed -i s/\`//g $file

backquote=\`
sed -i s/${backquote}//g $file

and some other things, but all returned the error:

sed: 1: "/Users/.....": invalid command code B.

I tried to find the explanation for this error, but to no avail. I hope somebody can tell me how to solve this problem.

Thanks,
Bj�rn

Have you tried with single quotes?

# echo 'somefile with `s' | sed 's/`//g'
somefile with s
# echo 'somefile with `s' | tr -d '`'
somefile with s

perl:

1 Like

CarloM, the command you posted works onscreen, but it does not alter the file itself. I need it to change it in the file itself, therefore I use the -i flag, but when doing that, it gives an error again. This time it's

invalid command code E

Any other suggestions?

---------- Post updated at 10:35 AM ---------- Previous update was at 10:32 AM ----------

Ooh, just saw kevintse's reply, and that works! Thanks man!

It works for me! :stuck_out_tongue:

# x.txt
somefile with `s
# sed -i 's/`//g' x.txt
# cat x.txt
somefile with s

(GNU sed 4.1.5)

If neither that or kevintse's code works for you then an alternative might be to write a shell script wrapper to use a temporary file.

with awk

echo 'testing`s' | awk -v a='`' '{gsub(a,"")}1'

Go with tr too ..

$ tr -ds '`' '' < infile