Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to use sed to substitute all the patterns with digits followed immediately by a dot (such as 3., 355.) by an empty string. So I try

sed 's/\d+\.//g' file.txt

But it doesn't work. Why is that?

share|improve this question

2 Answers 2

up vote 8 down vote accepted

Because sed is not perl -- sed regexes do not have a \d shorthand:

sed 's/[[:digit:]]\+\.//g'

sed regular expression documentation here.

share|improve this answer

Two problems:

  1. sed does not support \d. Use [0-9] or [[:digit:]].

  2. + must be backslashed to get the special meaning: \+.

share|improve this answer
    
instead of backslashing the + (which doesn't work on Mac OS X, for example) you can use the -E option to interpret regular expressions as extended (modern) regular expressions rather than basic regular expressions (BRE's). Sadly, this doesn't help with the \d issue... –  gmale Aug 6 '13 at 1:01
    
@gmale: -E does not work for GNU sed, it uses -r instead. –  choroba Aug 6 '13 at 6:54
1  
Okay... it sure looks like sed just sucks when it comes to portability... –  iconoclast Jul 14 at 15:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.