> ls /usr/playlists/*.m3u | while read -e FNAME
> do
>   sed -e 's/M:\\/\/usr\/mp3\//g' "$FNAME" > "${FNAME}2"
>   rm -f "$FNAME"
>   sed -e 's/\\/\//g' "${FNAME}2" > "$FNAME"
>   rm -f "${FNAME}2"
> done
>
> Any suggestions on improvements are welcome

A few points:

  - The '-e' is not necessary (and it even seems syntactically wrong,
    as it should expect a script file to read).
  - The first char right after the 's' in the sed command is the field
    separator. You have it set to '/', which then forces you to escape
    it when you want to use it as part of the string. If you instead
    choose a different separator, your sed command will become more
    readable.
  - You could use a generic temp file, which makes the code more readable.

Result:

   TMPFILE=/tmp/script.$$
   ls /usr/playlists/*.m3u | while read -e FNAME
   do
      sed 's|M:\\|/usr/mp3/|g' "$FNAME" > "${TMPFILE}"
      sed 's|\\|/|g' "${TMPFILE}" > "${FNAME}"
   done
   rm -f "${TMPFILE}"

Niek.

_______________________________________________
Discuss mailing list
[email protected]
http://lists.slimdevices.com/lists/listinfo/discuss

Reply via email to