I want to replace this string:

export TODO_FILE="$TODO_DIR/todo.txt


export TODO_FILE="$TODO_DIR/writing.txt"

in the file ~/.todo/config. I've run it with:

sed -i 's/export TODO_FILE="$TODO_DIR/todo.txt"/export TODO_FILE="$TODO_DIR/writing.txt"/g' ~/.todo/config

But it says:

sed: -i may not be used with stdin

What should I do?

  • 1
    For completeness, include your version of sed; usually gotten from: sed --version
    – KM.
    Feb 9 '15 at 17:40
  • I can't get my sed version using those commands.
    – rahmat
    Feb 12 '15 at 13:49

Try this (Chris, you're very close):

sed -i '' 's|export TODO_FILE="$TODO_DIR/todo.txt"|export TODO_FILE="$TODO_DIR/writing.txt"|g' ~/.todo/config
  • According to the sed man page the suffix is optional (and I tested my version). Why does this work? Feb 9 '15 at 17:17
  • Someone will correct me, but I believe this behavior varies by version. At least in mine, -i is not the same as -i ''. The former implies that the option is "not set" (for the lack of a better word) and not allowed; the latter implies that it is zero-length, and allowed. sed version: GNU sed 4.2.1, on RHEL 6.5; does not appear to be optional. HTH.
    – KM.
    Feb 9 '15 at 17:36
  • I'm testing with the same version of sed on RHEL 6.4. Also, I believe the empty quotes should be attached to the -i option or be used with = in the long parameter. Clearly my answer obviously didn't solve his problem, but I don't think adding empty quotes is the answer, especially if they're passed as an individual parameter. Feb 9 '15 at 19:15

Better first match the line and then just substitute the part

sed -i '/export TODO_FILE/ s/todo.txt/writing.txt/' ~/.todo/config

This becomes short when you have a path variable too long.

and as mentioned in the previous answer use some other separator when dealing with path.


I don't think the problem is the dollar sign because it's inside single quotes. Assuming you're using bash, strings inside single quotes are not variable expanded.

One of your problems is that you have picked a separator character (the first character after the "s" command) that exists in your find/replace strings -- "/". This is being interpreted by sed differently than what you're expecting. You should pick a different character that doesn't appear in your find/replace strings, such as "|".

sed -i 's|export TODO_FILE="$TODO_DIR/todo.txt"|export TODO_FILE="$TODO_DIR/writing.txt"|g' ~/.todo/config

However, that doesn't explain your particular error message.

Maybe you're using the BSD version which apparently treats the -i differently?

  • It still saying sed: -i may not be used with stdin. Do I miss something?
    – rahmat
    Feb 9 '15 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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