Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to change the path in whole lot of m3u files. I know I can do it with regexxer f.e. but I'm trying to learn bash.

This is the command I figured out, but it is not working.

grep -lr -i -e 'M:\\' * | xargs -0 sed -i 's/M:\\/T:\\/g'

I suspect, but only suspect, it is due to special characters in filenames. How to deal with that?

share|improve this question
First of all -0 option to xargs is wrong here, because it means the grep should send filenames separated by a NUL, which is not true (ok, it could be obtained by some grep option). Second, avoid using xargs in general, there are always better and safer ways to do the same thing. Lastly, it could help if you can show an input file, or at least some lines. – enzotib Aug 31 '11 at 16:45

Finaly I found the answer:

grep -lr -i -Z -e 'm:\\' * | xargs -0 sed -i 's/M:\\/K:\\/g'

I had to add the -Z to take care that every filename is read, and not the entire bunch in one long string.

share|improve this answer

This did the trick:

to change the windows path M:\ to the mount point in Ubuntu media/MODERNE MUZIEK

find -iname '*.m3u' -print0 | 
    xargs -0 sed -i 's/M:\\//\/media\/MODERNE\ MUZIEK\//g'

to change the the back slashes to forward slashes

find -iname '*.m3u' -print0 | xargs -0 sed -i 's/\\/\//g'

Now I can open my ex-windows m3u files with VLC player in Ubuntu.
It plays no matter how many spaces or weird characters are in the filename.

Could this be improved? could it be done with grep to make it conditional as in my first failed try? Why did grep not work?

Thanks for the input.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.