Hi, I posed this question last week, but in the wrong catagory - which is probably why it went unsolved/stale.
(
http://www.linuxquestions.org/questi...iables-753788/)
In short, my question pertains to using sed w/ Windows environment variables (ie. %CD%) on a Windows machine.
Sed is not parsing the backslashes correctly in my environment variable.
I am trying to build a (web) playlist. I can easily dump filenames to file in this format:
Code:
D:\shares\Music\Mixtape (Various Artists)\01 Chick Habit.mp3
What I need help with is modifying that to this format:
Code:
http://25.25.255.255/01 Chick Habit.mp3
Current test.bat:
Code:
@echo off
REM Set variable "%web_path%"
echo Type your web address below (ie. www.somesite.com or external IP).
set /p web_path=Web address:
REM Dump "%CD%" (Windows environment variable for current direcotry) to temp batch for processing with sed
echo set CD2=%CD% >var.bat
REM Replace "\" with "\\"
sed -e "s,\\,\\\\,g" var.bat >var2.bat
REM Set variable "%CD2%"
call var2.bat
REM Dump filenames w/ path to "tmp"
dir /s/b > tmp
REM (Supposed to) Replace every instance of "%CD%" w/ "http://%web_path%"
sed -e "s,%CD2%,http://%web_path%,g" tmp >tmp2
REM Finally, replace any "\" with "/"
sed -e "s,\\,/,g" tmp2 >tmp3
ren tmp3 playlist.m3u
The only line that doesn't work is "sed -e "s,%CD2%,http://%web_path%,g" tmp >tmp2", however if I replace "%CD2%" with the path directly in the command (using double backslashes), it works fine!
To clarify, this works:
Code:
sed -e "s,D:\\shares\\Music,http://%web_path%,g" tmp >tmp2
This does not:
Code:
sed -e "s,%CD2%,http://%web_path%,g" tmp >tmp2
What is "%CD2%"?
Code:
C:\>echo %CD2%
D:\\shares\\Music
"%CD2%" and the path typed in the last sed command are identical. Why doesn't this variable work?
