sed guru required for help with Win32 environment variables
SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
sed guru required for help with Win32 environment variables
My example (Keep in mind this is in a Windows environment):
Code:
set /p web_path=Web address:
dir /s/b > tmp
sed-3.59 -e s,%CD%,http:\\%web_path%,g tmp >playlist.m3u
I am trying to convert the above dir output to a web friendly MP3 playlist, however, I have discovered sed doesn't parse slashes and backslashes the way I'd like (especially in the above Windows environment variables). Is there a solution to this?
not sure how this is slackware related.... and I am by no means a sed guru - but with sed you can use slashes, and other characters of this type - you just have to escape these characters with a backslash. like so ::
so the sed command above is taking the line "http:\\www.yahoo.com" (well, just the http:// part is what matches) and changing changing it to "http://www.yahoo.com".
D:/shares/Music/Mixtape (Various Artists)/01 Chick Habit.mp3
D:/shares/Music/Mixtape (Various Artists)/01 Mr. Self Destruct.mp3
D:/shares/Music/Mixtape (Various Artists)/01 Queen B.mp3
D:/shares/Music/Mixtape (Various Artists)/01 Somewhat Damaged.mp3
D:/shares/Music/Mixtape (Various Artists)/02 - king cobb steelie - below the stars.mp3
D:/shares/Music/Mixtape (Various Artists)/02 - Natural one - The Folk Implosion.mp3
D:/shares/Music/Mixtape (Various Artists)/02 Piggy.mp3
D:/shares/Music/Mixtape (Various Artists)/03 Vagina Mine.mp3
D:/shares/Music/Mixtape (Various Artists)/03 Where Is Everybody-.mp3
D:/shares/Music/Mixtape (Various Artists)/04 Don't You Evah.mp3
D:/shares/Music/Mixtape (Various Artists)/04 Momma Sed.mp3
D:/shares/Music/Mixtape (Various Artists)/04 The Wretched.mp3
D:/shares/Music/Mixtape (Various Artists)/05 - something's burning.mp3
D:/shares/Music/Mixtape (Various Artists)/05 A Million Hearts.mp3
D:/shares/Music/Mixtape (Various Artists)/05 Closer.mp3
D:/shares/Music/Mixtape (Various Artists)/05 Drunk with Power.mp3
D:/shares/Music/Mixtape (Various Artists)/05 kids oracular spectacular mgmt.mp3
D:/shares/Music/Mixtape (Various Artists)/05 We're in This Together.mp3
D:/shares/Music/Mixtape (Various Artists)/06 The Fragile.mp3
D:/shares/Music/Mixtape (Various Artists)/06 The Undertaker.mp3
D:/shares/Music/Mixtape (Various Artists)/06. Pale 3 feat. 12 Rounds - Just Another Day.mp3
D:/shares/Music/Mixtape (Various Artists)/07 lazy eye.mp3
D:/shares/Music/Mixtape (Various Artists)/07 The Becoming.mp3
D:/shares/Music/Mixtape (Various Artists)/07 Trekka.mp3
D:/shares/Music/Mixtape (Various Artists)/07-johnny_hollow-superhero.mp3
D:/shares/Music/Mixtape (Various Artists)/08 Even Deeper.mp3
D:/shares/Music/Mixtape (Various Artists)/08 I'm Looking Forward to Joining You, Finally.mp3
D:/shares/Music/Mixtape (Various Artists)/08 Indigo Children.mp3
D:/shares/Music/Mixtape (Various Artists)/09 Eyes on Fire.mp3
D:/shares/Music/Mixtape (Various Artists)/09 The Big Come Down.mp3
D:/shares/Music/Mixtape (Various Artists)/10 No, You Don't.mp3
D:/shares/Music/Mixtape (Various Artists)/10 Rev. 22-20 [Dry Martini Mix].mp3
D:/shares/Music/Mixtape (Various Artists)/12 Reptile.mp3
D:/shares/Music/Mixtape (Various Artists)/14 - pleasent smell (rethought by trent reznor).mp3
D:/shares/Music/Mixtape (Various Artists)/16 chick habit.mp3
D:/shares/Music/Mixtape (Various Artists)/41 - Pigface - Sweetmeat.mp3
D:/shares/Music/Mixtape (Various Artists)/beck - 01 - loser.mp3
D:/shares/Music/Mixtape (Various Artists)/Cake - Short Skirt Long Jacket.mp3
D:/shares/Music/Mixtape (Various Artists)/detachable penis_king missle.mp3
D:/shares/Music/Mixtape (Various Artists)/Donnie Darko - 17 - Gary Jules - Mad World.mp3
D:/shares/Music/Mixtape (Various Artists)/Donnie Darko Score - 18 - Gary Jules - Mad World (Alternate Version).mp3
D:/shares/Music/Mixtape (Various Artists)/joyous.mp3
D:/shares/Music/Mixtape (Various Artists)/Nine Inch Nails - 08 - Eraser (Polite).mp3
D:/shares/Music/Mixtape (Various Artists)/pleasant smell.mp3
I don't need to post a sample of tmp3 because it is identical to tmp2 . When fiddling w/ the script, I found substituting the variable %CD2% for just something like "Music" *DOES* substitute every instance of "Music" with the variable set as %web_path2%.
You run sed under Windows and ask the question in the Slackware forum?
Sure, why not? The OP might be trying to convert playlists. Also, the GNU utilities provides a sed command that works in Windows. I have used the tools myself because the stock Windows has no such tools.
Sure, why not? The OP might be trying to convert playlists. Also, the GNU utilities provides a sed command that works in Windows. I have used the tools myself because the stock Windows has no such tools.
I use most of the GNU tools under Windows at the office, as I cannot make my mind use "dir" or "type" or remember the right syntax for all the Windows commands.
Actually, I use cygwin for this...
I just was surprised as I have seen many threads being moved from here to other forums as they had no connection to Slackware.
The OP did not state any reason to have posted here, but I'll try to help anyway if I can.
Ok, I tested your scripts after installing the Win32 version of sed on my Windows machine and everything just worked fine.
The difference is that my sed version for Windows is 4.2
Maybe some bugs have been resolved...
You could try separating the passes, like:
Code:
sed -e "s,\\,/,g" tmp > tmp2
sed -e "s,%CD2%,%web_path2%,g" tmp2 >tmp3
Your syntax should work though, it worked fine here, on Windows XP with sed 4.2
niels.horn: You actually did that? Thank you! I took your advice and updated to 4.2, but I am still getting the same result. I modified my test.bat, and am closer. Now I can illustrate my issue much more clearly.
Woodsman is correct. I am trying to build a (web) playlist. I can easily dump filenames to file in this format:
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?
I use most of the GNU tools under Windows at the office, as I cannot make my mind use "dir" or "type" or remember the right syntax for all the Windows commands.
Actually, I use cygwin for this..
I'm an Administrator for Windows-networks and I've vim (the windows-version) installed on most servers in order to edit scripts in a convenient way. Also I've installed vim on an USB-Stick, so I can use it on all client-PCs.
And many of my scripting for the windowsworld I do on Linux-machines.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.