I am trying to use \d in regex in sed but it doesn't work:
sed -re 's/\d+//g' But this is working:
sed -re 's/[0-9]+//g' \d is a switch not a regular expression macro. If you want to use some predefined "constant" instead of [0-9] expression just try run this code:
s/[[:digit:]]+//g \w works\d has different meaning in sed.There is no such special character group in sed. You will have to use [0-9].
In GNU sed, \d introduces a decimal character code of one to three digits in the range 0-255. As indicated in this comment.
You'd better use the Extended pattern in sed by adding -E. In basic RegExp, \d and some others won't be detected -E Interpret regular expressions as extended (modern) regular expressions rather than basic regular expressions (BRE's). The re_format(7) manual page fully describes both formats.
\d won't be detected with -E either.
perl -pe 's/\d+//g'or rather that's what I need to use to get it to print out a file (so using it in the form:perl -pe 's/\d+//g' example.txt > example2.txt) were you suggesting a different usage?\ddoesn't represent a digit in sed. The question referenced as a duplicate is about "How to extract text from a string using sed."