Using Sed under CMD.exe (windows)
I've been looking for a utility to so a simple search and replace string so I downloaded Sed from http://unxutils.sourceforge.net/.
What I want to do is actually a search and replace on Pathname and I want to pass a CMD environment like %HOMEPATH% or %CD%. But the problem arises becuase Sed sees the single slashes in those environment as delimeters. Is there anyway to work around this? I don't have to use Sed, but I want it to be a small self contained executable. I don't want to install a full blown scripting language like Perl or Python just to do this. |
You can use (almost) any delimiter in s commands:
This: Code:
sed -n 's/^searchstring/foundstring/p' file.txt Code:
sed -n 's,^searchstring,foundstring,p' file.txt Code:
sed -n 's|^searchstring|foundstring|p' file.txt Code:
sed -n '|searchstring|p' |
The problem is that even if you use another delimiter, it still won't treat the single '\' as a literal. It still treats this as some kind of operand.
I guess sed doesn't work with variables that contain a path name.. I guess I have to try something else. |
You could pipe through tr and replace the slashes (which
to sed indeed are escape characters) with "|" for example, and then do the search and replace, and tr again afterwards. Cheers, Tink |
Thanks, you pointed me in the right direction. I had to figure out what 'tr' was. It turned out to be in the list of WIN 32GNU utilities as well. However, I had to use '?' as the delimiter because it was the only character that was neither a) an operand for the 'tr' or 'sed' nor b) a legal character for a windows file/folder name.
To get this to work, I had to do something like echo set WINPATH_TR=%WINPATH%|tr '\\' '?' > WINPATH_TR.bat call WINPATH_TR.bat del WINPATH_TR.bat This would then set WINPATH_TR to something like c:?windows?system which I could pass down to sed. (I'm not familiar with the affero) |
Congratulations :)
Cheers, Tink |
All times are GMT -5. The time now is 11:48 PM. |