yahoo
December 20, 2012, 10:47am
1
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
Scott
December 20, 2012, 10:51am
2
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.
yahoo
December 20, 2012, 10:57am
3
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
Scott
December 20, 2012, 10:59am
4
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.
yahoo
December 20, 2012, 11:06am
5
#!/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
Scott
December 20, 2012, 11:08am
6
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.
yahoo
December 20, 2012, 11:18am
7
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
hexram
December 20, 2012, 11:51am
8
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.
yahoo
December 20, 2012, 11:57am
9
Thanks for your reply!!!
Anyone using cygwin can please confirm if it works
RudiC
December 20, 2012, 1:15pm
10
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...