Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Using the Ubuntu 12.04 and vim 2.22.0, why inside the vim I shall use:


to change first digit of the mentioned line to 1, but couldn't be able to use the same with sed as :

sed -i '9s/\d\+/1/' /home/file/foo

I still don't get any error neither any changes in the file. Do we have any inconsistency between the functionalities of vim and sed command ?

share|improve this question
up vote 4 down vote accepted

sed and vim are not related (well sort of, but it's far out). Their substitution commands are similar, but far from identical. Both of them use basic regular expressions, but vim has its extensions for it, and GNU sed has other extensions for it.

\d matches a digit in vim, in GNU sed it matches a d. To match a digit in sed, use [[:digit:]] or [0-9] (and those will also work in vim).

\+ is also an extension in both vim and GNU sed. The standard way to match one or more is to use \{1,\} instead.

share|improve this answer
tnx for the reply. but still now by using ":9s/[0-9]{1,\}/1/" it can not match the mentioned digit – Amir Jul 30 '13 at 21:31
Simply I tried everything, but it didn't work out. do you have a clean answer buddy ? – Amir Jul 31 '13 at 0:30
@Amir seems askubuntu decided to wrap that line after the first character. You're missing the backslash in front of {. sed '9s/[0-9]\{1,\}/1/'. You could also write it sed '9s/[0-9][0-9]*/1/'. – geirha Jul 31 '13 at 5:39
Tnx @geirha for the answer;) – Amir Jul 31 '13 at 12:26

Your Answer


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.