Regex not matching

regular expressionsed

why this does not match..?

sed -e '/--Updated?[[:space:]]+Date/d' inputfile

this..:

--Updated Date: 2013-11-06 15:32:13

d? is because sometimes I have Update Date, and sometimes Updated Date.

for removal? I have tried with \s too, not working.

Best Answer

you need to use the -r parameter. try use

sed -r '/--Updated?[[:space:]]+Date/d' inputfile

updating answer

When you use sed '/something/d' , every line that match with this will be deleted.

-r - the parameter -r is use extended regular expressions .

Inside the expression have 2 regular expressions.

[[:space:]] - Match with all whitespace characters, including line breaks

? - optional

+ - one or more times.

SO, the command sed will delete every line that match with --updated and than one or more whitespace character and than Date but because of the ? the character d is optional. like:

--Updated Date: 2013-11-06 15:32:13
--Updated   Date: 2013-11-06 15:32:13
--Updated           Date: 2013-11-06 15:32:13
--Update Date: 2013-11-06 15:32:13
Related Question