I have lines with a single :
and a\'
in them that I want to get rid of. I want to use awk
for this. I\'ve tried using:
You could use:
Octal code for the single quote:
[:\47]
The single quote inside double quotes, but in that case special characters will be expanded by the shell:
% print a\': | awk "sub(/[:']/, x)"
a
Use a dynamic regexp, but there are performance implications related to this approach:
% print a\': | awk -vrx="[:\\\']" 'sub(rx, x)'
a
With bash you cannot insert a single quote inside a literal surrounded with single quotes. Use '"'"'
for example.
First '
closes the current literal, then "'"
concatenates it with a literal containing only a single quote, and '
reopens a string literal, which will be also concatenated.
What you want is:
awk '{gsub ( "[:'"'"']","" ) ; print $0; }'
ssapkota's alternative is also good ('\''
).
This works:
awk '{gsub( "[:'\'']","" ); print}'
This also works:
awk '{gsub("\x27",""); print}'
I don't know why you are restricting yourself to using awk, anyways you've got many answers from other users. You can also use sed to get rid of " :' "
sed 's/:\'//g'
This will also serve your purpose. Simple and less complex.
simplest
awk '{gsub(/\047|:/,"")};1'