I am removing duplicated lines of text from a number of files. The command I am trying to use is

sed -i 's/set autologout=10//g' /home/$x/.login

When I run it, I get this error

sed: -I or -i may not be used with stdin

The command runs successfully without the -i option however it doesn't save it. I am scripting this out as I am modifying 2 files per account on each server. I can code this out with one ugly exception, I can't get it to save.

  • I think the -e flag will work in sed. But there is another way to do this without sed (multiple ways). One way im thinking is: cat file.txt | uniq >> otherfile.txt may work..
    – ryekayo
    Mar 14, 2017 at 19:11
  • yes I am on BSD, I will give that a shot]
    – Steve
    Mar 14, 2017 at 19:15

2 Answers 2


What @don_crissti's comment refers, is the fact that BSD sed seems to require an argument for -i, and if -e isn't used, the first argument is taken as the sed command. Which leaves none for the input file, defaulting to stdin, and you can't edit that "in-place".

That's as opposed to, say, GNU sed, which has -i take an optional argument.

Or in other words, your sed may be interpreting the s/set autologout=10//g as a parameter to -i, the extension to use for the backup file. So if you don't want to leave a backup file, just give the -i option an empty argument:

sed -i "" 's/set autologout=10//g' /home/$x/.login
  • PERFECT !!! sed -i '' -e solved the problem. THANKS !!
    – Steve
    Mar 14, 2017 at 19:17
  • Also -i "" worked as well !
    – Steve
    Mar 14, 2017 at 19:20

For POSIX solution, you can use Vim in Ex mode:

ex -sc '%s/set autologout=10//g|x' /home/"$x"/.login
  1. % select all lines

  2. | command separator

  3. x write to file if changes have been made (they have) and exit

  4. "$x" bad to leave variable unquoted in this case

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .