I'm trying to do the following, but either I'm way too tired and can't think, or something weird is hapening with the escapes:
scanimage -L | gawk '/N650U/ {print gensub("[\'`]", "", "g", $2)}'
pipe bquote>
I'm trying to do the following, but either I'm way too tired and can't think, or something weird is hapening with the escapes:
scanimage -L | gawk '/N650U/ {print gensub("[\'`]", "", "g", $2)}'
pipe bquote>
The idiom to do this is to create a variable which contains the single quote and then use that:
However, since you are using it in a character class, that is not going to work so you'll need to do this:
Another alternative if using
bash
is to use$''
which does support escaping single-quotesAll you are doing in the 2nd case is creating a single-quote pair right before your literal single-quote, escaping the single quote so the shell doesn't interpret it and then make another single-quote pair after it.
Example with single-quote in a regex
Example with single-quote outside a regex
Example with single-quote inside
$''
Shell '...' doesn't support backslash escapes. You'll have to use "..." instead, I'm afraid.
(Note that shell "..." does expand $ variables, so you need to escape that as well!)
There's no special character in single quotes including backslash(
\
).You can change the command to:
The correct way to do this is simply:
It doesn't affect using
\047
for a single quote but as an aside given all of the other posted solutions are using string delimiters, note the use of regexp delimiters instead of string delimiters around the regexp that is gsub()s first argument. It matters, see for example:The only time to use string delimiters in a regexp context is when you need to concatenate a literal with a variable, e.g.:
Look up string and regexp delimiters in the man page for details.
A bit ugly, but this works: