sed -i option giving error no such file or directory

I created a shell with sed -i option. It is giving error - No such file or directory

Ex -

 
sed -i 's/yes/no' yes.txt
sed -i 's/why/where' yes.txt
sed -i 's/when/how' yes.txt
 
Error - :No such file or directory

When I run single line in my script say sed -i 's/yes/no' yes.txt it works

PLEASE HELP ASAP

First off, please use code tags when posting code. Secondly do not post asking for help "ASAP", or I will close your thread. And thirdly your sed has an error in it. The syntax for a subsitution is s/old/new/ , and lastly does the file yes.txt exist?

You are using -i. Does that require that you provide a backup filename? The man page will tell you.

Thanks for your reply. Even if I use correct format s/old/new/ I am getting this error

---------- Post updated at 10:57 AM ---------- Previous update was at 10:53 AM ----------

When I run only single line in my script its working

sed -i 's/old/new/' yes.txt

but with multiple commands it doesnt

Can you post the contents of your script exactly as displayed using cat -v scriptname ?

Please also say which OS (incl. version) and shell you are using.

#!/bin/sh

sed -i 's/yes/no/' yes.txt

sed -i 's/why/where/' yes.txt
sed -i 's/when/how/' yes.txt

---------- Post updated at 11:03 AM ---------- Previous update was at 11:03 AM ----------

 
#!/bin/sh
sed -i 's/yes/no/' yes.txt
sed -i 's/why/where/' yes.txt
sed -i 's/when/how/' yes.txt

---------- Post updated at 11:06 AM ---------- Previous update was at 11:03 AM ----------

I am trying from cygwin, bash Shell sh, windows 7

OK, I have no idea about that. Try using double quotes instead.

And check that the -i option is supported in that version of sed.

yes -i option is present. It is working with single sed -i

-i[SUFFIX], --in-place[=SUFFIX]
edit files in place (makes backup if extension supplied)

---------- Post updated at 11:18 AM ---------- Previous update was at 11:13 AM ----------

Please some one try this code at their end to see if it works

OK. Here is what I have done:

File yes.txt (before):

yes
why
when
what

File yes.sh:

#!/bin/sh
sed -i 's/yes/no/' yes.txt
sed -i 's/why/where/' yes.txt
sed -i 's/when/how/' yes.txt

Made it executable:

chmod 754 ./yes.sh

Execute it:

./yes.sh

File yes.txt (after):

no
where
how
what

I'm happily using LinuxMint while it gets updated as needed, so I guess it is version 14 by now... Hope this helps.

Thanks for your reply!!!

Anyone using cygwin can please confirm if it works

Why don't you add a pwd and an ls -l to your script so you can see where it looks for the file yes.txt?

Why don't it works in CYGWIN. See my output from Cygwin screen

# cat > yes.txt
yes
why
when
what



# cat > yes.sh
#!/bin/sh
sed -i 's/yes/no/' yes.txt
sed -i 's/why/where/' yes.txt
sed -i 's/when/how/' yes.txt



# chmod 754 ./yes.sh


# ./yes.sh


# cat yes.txt
no
where
how
what

Please share us your error output...