Results 1 to 7 of 7
Hello everyone! This is my first post, so I'll try not to sound like a n00b. My scenario is this: I have a Motorola ROKR E6 Mobile (Which runs a ...
- 08-17-2007 #1Just Joined!
- Join Date
- Aug 2007
- Posts
- 8
Bash Scripting: Help needed for Sed command.
Hello everyone! This is my first post, so I'll try not to sound like a n00b. My scenario is this: I have a Motorola ROKR E6 Mobile (Which runs a MontaVista Mobile Linux). My Notebook is running Windows XP tablet Edition. I sync my music from the table to the ROKR successfully on a regular basis. However, I want the .M3U playlists to sync as well. When I do this, they sync in this format:
However, for the mobile to understand them, I need to have a script edit the M3U playlists (on the mobile) to this format:Code:\MyMusic\Artist - Title.MP3
The reason being, the memory card of the phone is mounted to /mmc/mmca1/ Now, I can't change that, it would be too much redirecting in part of ringtones, apps, etc. I can't have MediaMonkey sync the music and playlists to /mmc/mmca1/MyMusic/ as it will show up in the phone as /mmc/mmca1/mmc/mmca1/MyMusic/ which, for reasons obvious to us here, will not read on the phone.Code:/mmc/mmca1/MyMusic/Artist - Title.MP3
Anyhow, this is what I've come up w/ so far:
Here's where I'm at: I can get it to print on the screen what I want. But what I want is for it to save to the .M3U playlists. There are about 6 of them in a folder (/mmc/mmca1/MyMusic/Playlists). This is why it cd to that directory. I then have it search for \MyMusic\ and then replace w/ /mmc/mmca1/MyMusic/. But this is all I can think of. I've searched the web for about 3 weeks now, and have had no luck. I was thinking something like creating a loop that runs for each file in the directory. But, to be honest, my abilities in scripting are still a bit limited.Code:#!/bin/bash # M3U Fixer by Imahottguy cd /mmc/mmca1/MyMusic/Playlists sed 's_\\MyMusic\\_/mmc/mmca1/MyMusic/_g' *
- 08-17-2007 #2Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
This is an example to search for the .M3U files in the directory /mmc/mmca1/MyMusic/Playlists and to save the changes with the -i option:
RegardsCode:#!/bin/bash cd /mmc/mmca1/MyMusic/Playlists for file in $(ls *.M3U) do sed -i 's_\\MyMusic\\_/mmc/mmca1/MyMusic/_' "$file" done
- 08-17-2007 #3Just Joined!
- Join Date
- Aug 2007
- Posts
- 8
Sorry, but when I tried your example the prompt sput out this:
I then copied and pasted the script into UE and tried it again, no go... Any ideas? I've never seen the option 'I', what does it do? Perhaps the sed utility in my mobile is outdatedCode:sed: Invalid option -- I
EDIT:
After messing around, wouldn't the 'w' flag be the way to go? As in something like this:
This is what I'm theorizing... It locks up the bash prompt when I enter that in. So I'm sure that there are some discrepancies somewhere in the sed command.Code:#!/bin/bash cd /mmc/mmca1/MyMusic/Playlists # Since there is only M3U playlists in the folder i have it just ls for file in $(ls) do sed 's_\\MyMusic\\_/mmc/mmca1/MyMusic/_w $file' done
EDIT AGAIN:
I've gotten one playlist to change... But none others...
EDIT AGAIN::Code:#!/bin/bash cd /mmc/mmca1/MyMusic/Playlists # Since there is only M3U playlists in the folder i have it just ls for file in $(ls) do sed 's_\\MyMusic\\_/mmc/mmca1/MyMusic/_w $file' "$file" done
I was wrong, none have changed... Still workin' on it
- 08-17-2007 #4
The '-i' option means "modify the file in place" (as opposed to just printing the output to stdout). You can duplicate the behavior with:
Note that this will delete the playlist, and replace it with the modified one, so I suggest backing up your playlists until you have the sed command correct.Code:#!/bin/bash cd /mmc/mmca1/MyMusic/Playlists for file in $(ls *.M3U) do sed 's_\\MyMusic\\_/mmc/mmca1/MyMusic/_' "$file" > temp mv temp "$file" done
EDIT:
I am not familiar with the 'w' regex flag (nor do I believe it exists). What is it supposed to do?DISTRO=Arch
Registered Linux User #388732
- 08-17-2007 #5Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
- 08-17-2007 #6Just Joined!
- Join Date
- Aug 2007
- Posts
- 8
though it printed invalid option -- I, I had inputed a lowercase 'i' as in:
sed -i ...
@Cabhan: Thank you very much. Thanks to everyone who helped me! Your method of putting it in temp worked perfectly. The 'w' flag that I referred to was one I read about in tutorial for the sed command. Here is the link: Here. Thank you again.
Thanks to everyone who helped me!
I really appreciate it.
- 08-18-2007 #7Linux User
- Join Date
- Aug 2006
- Posts
- 458


Reply With Quote
