Discussion:
Need help with SED
goshainganj
2013-02-15 10:51:30 UTC
Permalink
@echo off
dir /b /s | find ".pscx" > mydir.txt
pushd .
for /F "delims==" %%a in (mydir.txt) do (
echo "%%a"
sed -i "s/1.0101/1.0400/g" "%%a" > junk.txt
move junk.txt "%%a"
)
popd
del mydir.txt
-------------------

I wrote the above code to change 1.0101 to 1.0400 in all .pscx files in all directories from where I am executing this batch file.

I read SED manual and it said -i option would directly change .pscx files but it complained. So I directed the output to junk.txt. I wanted to move junk.txt back to .pscx file. It is this part of the above script that's not working.

Any suggestions why -i is not working and how I can make the above to work?

Thanx
Kailash
Eliana
2013-02-15 15:33:18 UTC
Permalink
the bash command to rename files is mv, not move.

if this is in bash, try changing your line from

move junk.txt "%%a"

to the following

mv junk.txt "%%a"
Post by goshainganj
@echo off
dir /b /s | find ".pscx" > mydir.txt
pushd .
for /F "delims==" %%a in (mydir.txt)
do (
echo "%%a"
sed -i "s/1.0101/1.0400/g" "%%a" > junk.txt
move junk.txt "%%a"
)
popd
del mydir.txt
kn srivastava
2013-02-15 16:05:07 UTC
Permalink
This is a Win7 batch script. move is a valid command.

Thanx
Kailash
Post by Eliana
the bash command to rename files is mv, not move.
if this is in bash, try changing your line from
move junk.txt "%%a"
to the following
mv junk.txt "%%a"
Post by goshainganj
@echo off
dir /b /s | find ".pscx" > mydir.txt
pushd .
for /F "delims==" %%a in (mydir.txt)
do (
echo "%%a"
sed -i "s/1.0101/1.0400/g" "%%a" > junk.txt
move junk.txt "%%a"
)
popd
del mydir.txt
Amarendra Godbole
2013-02-15 16:24:31 UTC
Permalink
I place editing can be problematic which is why classic sed does not touch the original file. This is a gnu extension (a move to make it more user friendly but broken in my opinion). So you should have gnu sed on windows. Secondly make sure the -i switch is not broken for your version. Thirdly tell us what does it complain and maybe I can help further.

-ag

--
sent via 100% recycled electrons from my mobile command center.
Post by goshainganj
@echo off
dir /b /s | find ".pscx" > mydir.txt
pushd .
for /F "delims==" %%a in (mydir.txt) do (
echo "%%a"
sed -i "s/1.0101/1.0400/g" "%%a" > junk.txt
move junk.txt "%%a"
)
popd
del mydir.txt
-------------------
I wrote the above code to change 1.0101 to 1.0400 in all .pscx files in all directories from where I am executing this batch file.
I read SED manual and it said -i option would directly change .pscx files but it complained. So I directed the output to junk.txt. I wanted to move junk.txt back to .pscx file. It is this part of the above script that's not working.
Any suggestions why -i is not working and how I can make the above to work?
Thanx
Kailash
------------------------------------
--
Yahoo! Groups Links
kn srivastava
2013-02-15 17:56:17 UTC
Permalink
sed: cannot rename ./sedDOSSUX: File exists

I get the above message.

Regards
Kailash

On Fri, Feb 15, 2013 at 5:24 PM, Amarendra Godbole
Post by Amarendra Godbole
I place editing can be problematic which is why classic sed does not touch the original file. This is a gnu extension (a move to make it more user friendly but broken in my opinion). So you should have gnu sed on windows. Secondly make sure the -i switch is not broken for your version. Thirdly tell us what does it complain and maybe I can help further.
-ag
--
sent via 100% recycled electrons from my mobile command center.
Post by goshainganj
@echo off
dir /b /s | find ".pscx" > mydir.txt
pushd .
for /F "delims==" %%a in (mydir.txt) do (
echo "%%a"
sed -i "s/1.0101/1.0400/g" "%%a" > junk.txt
move junk.txt "%%a"
)
popd
del mydir.txt
-------------------
I wrote the above code to change 1.0101 to 1.0400 in all .pscx files in all directories from where I am executing this batch file.
I read SED manual and it said -i option would directly change .pscx files but it complained. So I directed the output to junk.txt. I wanted to move junk.txt back to .pscx file. It is this part of the above script that's not working.
Any suggestions why -i is not working and how I can make the above to work?
Thanx
Kailash
------------------------------------
--
Yahoo! Groups Links
Daniel
2013-02-17 19:04:21 UTC
Permalink
What does sed -v or sed --version say?
Always helpful to know what version.

What is the error message when you don't
use -i and use "move junk.txt" instead?

s/1\.0101/1.0400/g is safer (very picky).

Does it work without the "%%a" syntax?
In other words, try a simple case first,
to narrow down where the problem is.

Daniel
Post by kn srivastava
sed: cannot rename ./sedDOSSUX: File exists
I get the above message.
Regards
Kailash
On Fri, Feb 15, 2013 at 5:24 PM, Amarendra Godbole
Post by Amarendra Godbole
I place editing can be problematic which is why classic sed does not touch the original file. This is a gnu extension (a move to make it more user friendly but broken in my opinion). So you should have gnu sed on windows. Secondly make sure the -i switch is not broken for your version. Thirdly tell us what does it complain and maybe I can help further.
-ag
--
sent via 100% recycled electrons from my mobile command center.
Post by goshainganj
@echo off
dir /b /s | find ".pscx" > mydir.txt
pushd .
for /F "delims==" %%a in (mydir.txt) do (
echo "%%a"
sed -i "s/1.0101/1.0400/g" "%%a" > junk.txt
move junk.txt "%%a"
)
popd
del mydir.txt
-------------------
I wrote the above code to change 1.0101 to 1.0400 in all .pscx files in all directories from where I am executing this batch file.
I read SED manual and it said -i option would directly change .pscx files but it complained. So I directed the output to junk.txt. I wanted to move junk.txt back to .pscx file. It is this part of the above script that's not working.
Any suggestions why -i is not working and how I can make the above to work?
Thanx
Kailash
------------------------------------
--
Yahoo! Groups Links
kn srivastava
2013-02-20 13:09:25 UTC
Permalink
GNU sed version 4.1.5
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,
to the extent permitted by law.
Post by Daniel
What does sed -v or sed --version say?
Always helpful to know what version.
What is the error message when you don't
use -i and use "move junk.txt" instead?
s/1\.0101/1.0400/g is safer (very picky).
Does it work without the "%%a" syntax?
In other words, try a simple case first,
to narrow down where the problem is.
Daniel
Post by kn srivastava
sed: cannot rename ./sedDOSSUX: File exists
I get the above message.
Regards
Kailash
On Fri, Feb 15, 2013 at 5:24 PM, Amarendra Godbole
Post by Amarendra Godbole
I place editing can be problematic which is why classic sed does not touch the original file. This is a gnu extension (a move to make it more user friendly but broken in my opinion). So you should have gnu sed on windows. Secondly make sure the -i switch is not broken for your version. Thirdly tell us what does it complain and maybe I can help further.
-ag
--
sent via 100% recycled electrons from my mobile command center.
Post by goshainganj
@echo off
dir /b /s | find ".pscx" > mydir.txt
pushd .
for /F "delims==" %%a in (mydir.txt) do (
echo "%%a"
sed -i "s/1.0101/1.0400/g" "%%a" > junk.txt
move junk.txt "%%a"
)
popd
del mydir.txt
-------------------
I wrote the above code to change 1.0101 to 1.0400 in all .pscx files in all directories from where I am executing this batch file.
I read SED manual and it said -i option would directly change .pscx files but it complained. So I directed the output to junk.txt. I wanted to move junk.txt back to .pscx file. It is this part of the above script that's not working.
Any suggestions why -i is not working and how I can make the above to work?
Thanx
Kailash
------------------------------------
--
Yahoo! Groups Links
------------------------------------
--
Yahoo! Groups Links
Daniel
2013-03-11 00:30:19 UTC
Permalink
Seems quite odd the file name is sedDOSSUX :) Does
it really say DOS SUX? Someone has a sense of humor!

I don't know if it explains the problem, but it
makes no sense to use both -i and "> junk.txt".
Use one or the other, but not both.

You had it:

sed -i "s/1.0101/1.0400/g" "%%a" > junk.txt
move junk.txt "%%a"

Instead, use either:

sed -i "s/1.0101/1.0400/g" "%%a"

Or:

sed "s/1.0101/1.0400/g" "%%a" > junk.txt
move junk.txt "%%a"
Post by kn srivastava
GNU sed version 4.1.5
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,
to the extent permitted by law.
Post by Daniel
What does sed -v or sed --version say?
Always helpful to know what version.
What is the error message when you don't
use -i and use "move junk.txt" instead?
s/1\.0101/1.0400/g is safer (very picky).
Does it work without the "%%a" syntax?
In other words, try a simple case first,
to narrow down where the problem is.
Daniel
Post by kn srivastava
sed: cannot rename ./sedDOSSUX: File exists
I get the above message.
Regards
Kailash
On Fri, Feb 15, 2013 at 5:24 PM, Amarendra Godbole
Post by Amarendra Godbole
I place editing can be problematic which is why classic sed does not touch the original file. This is a gnu extension (a move to make it more user friendly but broken in my opinion). So you should have gnu sed on windows. Secondly make sure the -i switch is not broken for your version. Thirdly tell us what does it complain and maybe I can help further.
-ag
--
sent via 100% recycled electrons from my mobile command center.
Post by goshainganj
@echo off
dir /b /s | find ".pscx" > mydir.txt
pushd .
for /F "delims==" %%a in (mydir.txt) do (
echo "%%a"
sed -i "s/1.0101/1.0400/g" "%%a" > junk.txt
move junk.txt "%%a"
)
popd
del mydir.txt
-------------------
I wrote the above code to change 1.0101 to 1.0400 in all .pscx files in all directories from where I am executing this batch file.
I read SED manual and it said -i option would directly change .pscx files but it complained. So I directed the output to junk.txt. I wanted to move junk.txt back to .pscx file. It is this part of the above script that's not working.
Any suggestions why -i is not working and how I can make the above to work?
Thanx
Kailash
------------------------------------
--
Yahoo! Groups Links
------------------------------------
--
Yahoo! Groups Links
Paolo Bonzini
2013-03-11 09:13:13 UTC
Permalink
Post by Daniel
Seems quite odd the file name is sedDOSSUX :) Does
it really say DOS SUX? Someone has a sense of humor!
I don't know if it explains the problem, but it
makes no sense to use both -i and "> junk.txt".
Use one or the other, but not both.
Get a newer sed from wherever you got it. That binary must be 10 years
old or so.

Paolo
kn srivastava
2013-03-11 11:47:53 UTC
Permalink
Post by Paolo Bonzini
Get a newer sed from wherever you got it. That binary must be 10 years
old or so.
Thank you for the help. Where from do I download new sed for 64 bit
Win7? I did google and found several sources. I downloaded one that
complained something is missing on my computer. Need your help in
identifying the right build.

Thanx
Kailash
Paolo Bonzini
2013-03-11 12:46:08 UTC
Permalink
Post by kn srivastava
Post by Paolo Bonzini
Get a newer sed from wherever you got it. That binary must be 10 years
old or so.
Thank you for the help. Where from do I download new sed for 64 bit
Win7? I did google and found several sources. I downloaded one that
complained something is missing on my computer. Need your help in
identifying the right build.
I honestly have no idea. But you should reject anything that is not sed
4.2.x.

Paolo

Loading...