user3299633
user3299633

Reputation: 3390

sed will not remove single quote

I've tried several different formats, but none of them are working. Any assistance would be appreciated:

[root@home:/home/users/jlefler]$ sed "s/[',#,`,@]//g" stage_data.out > stage_data
> ^C
[root@home:/home/users/jlefler]$ sed "s/[\',#,`,@]//g" stage_data.out > stage_data
> ^C
[root@home:/home/users/jlefler]$ sed "s/[#,`,@,\\']//g" stage_data.out > stage_data
> ^C

Upvotes: 1

Views: 1084

Answers (3)

that other guy
that other guy

Reputation: 123690

Let's ask shellcheck:

sed "s/[',#,`,@]//g" stage_data.out > stage_data
            ^-- SC1073: Couldn't parse this backtick expansion.

The backtick is the problem, not the single quote. Just escape it:

sed "s/[',#,\`,@]//g" stage_data.out > stage_data

Here's an example of this in action:

$ echo "'#@foo" > stage_data.out
$ sed "s/[',#,\`,@]//g" stage_data.out > stage_data
$ cat stage_data
foo

Upvotes: 2

Gilles Quénot
Gilles Quénot

Reputation: 185841

Try this one :

sed "s/[',#,\`,@]//g"

Upvotes: 1

o11c
o11c

Reputation: 16156

Your problem is caused by sh, not by sed.

Double quotes still allow certain special characters to have special meanings, such as $ and, in this case `.

This works:

echo "a'b'c" | sed -e "s/['#\`@]//g"

Or you could avoid all shell-related problems by sticking your patterns in a file and using sed -f

Upvotes: 3

Related Questions