0

I keep getting this error message and don't understand why. How do I fix it. I am using the bash shell on a Unix system.

$ sed -i 's/ he/ she/g' S13a4sed
sed: illegal option -- i
sat
  • 14,589
  • 7
  • 46
  • 65
mfb
  • 1
  • what UNIX system are you on? What is your sed version? – fedorqui Apr 10 '18 at 07:52
  • About `sed` tag: _Sed (Stream EDitor) is a command line editor for POSIX environment. Sed processes one or more files according to an editing script and writes the results to standard output. Created at Bell Labs, it has been around since the mid-70s. Use this tag only if your question relates to programming using sed or sed-based APIs. Questions relating to using or troubleshooting sed command-line options itself are off-topic._ – James Brown Apr 10 '18 at 07:52
  • this might help: https://stackoverflow.com/questions/5694228/sed-in-place-flag-that-works-both-on-mac-bsd-and-linux – Sundeep Apr 10 '18 at 07:54
  • im not to sure im using a program called putty for school to access unix servers called gator. I also tried sed i 's/ he/ she/g' S13a4sed but then it comes back with command grabled: – mfb Apr 10 '18 at 07:54
  • do you need the `-i` option? try `sed 's/ he/ she/g' S13a4sed` and let us know if that works – Sundeep Apr 10 '18 at 07:55
  • @Sundeep Yes it does work but I need to insert it. I am trying to change 4 sets of words and have them all apear on the file together. This is why i thought -i would be the best option – mfb Apr 10 '18 at 07:58
  • you could specify [multiple commands](https://www.gnu.org/software/sed/manual/sed.html#Multiple-commands-syntax) in single sed invocation.. that information is missing from question.. if you add sample lines and expected output, ppl would likely help you better.. – Sundeep Apr 10 '18 at 08:01

2 Answers2

0

sed command parameter option i is not available in some of the unix environment, for example SunOS Just use like below it will work for you.

 $ sed 's/ he/ she/g' S13a4sed

Just test it like below:-

 echo " he is a girl" | sed 's/ he/ she/g'

Output

    she is a girl   
Abhijit Pritam Dutta
  • 5,521
  • 2
  • 11
  • 17
0

sed's -i option is a feature of GNU's sed. Unfortunately you can't use it on your system. But you can use perl as well:

$ cat S13a4sed 
he is a girl
$ perl -pi -e 's/he/she/g' S13a4sed
$ cat S13a4sed
she is a girl

From here: sed -i + what the same option in SOLARIS

Konstantin Vustin
  • 6,521
  • 2
  • 16
  • 32