grep -v "#EXTINF:" All.m3u | sed 's#../##'g

I'm using the line above to try and make the playlists that I export from Banshee compatible with my digital music player. When I run the sed portion of this script I'm trying to remove the portion of the path up to where the music directories actually start. I jus want the .m3u file to be a list of lines containing Artists/Album/Title.flac

But when I run this script it's removing all of the forward slashes /, not just the beginning ../
Can anyone tell me why it's removing all of the forward slashes and what I might be able to do about it? Thanks.

Dani AI

Generated

Short answer: the dots in your sed pattern are regular-expression wildcards, so your expression matched "any two characters then a slash" and removed lots more than the literal "../". wanted to strip the literal parent-directory token; was right to point at escaping, but the exact escaping depends on quoting and which sed features you use.

A safe fix that removes every literal ../ is:

sed 's#\.\./##g'

Notes: using # as the delimiter avoids escaping /. Each \. makes the dot literal. Keep the g inside the quotes. With single quotes the shell passes backslashes straight through, so you only need one backslash per dot.

If you only want to remove leading parent-directory components (so internal slashes and directory names are preserved), use an anchored expression. With a sed that supports extended regex:

sed -E 's#^(\.\./)+##'

If your sed does not support -E, use the POSIX basic form (escape the grouping/quantifier):

sed 's#^\(\.\./\)\{1,\}##'

Quick troubleshooting tips: test on a few sample lines first (for example with printf or echo piped to sed) before changing the playlist file in place. Don’t run in-place edits until happy — use a backup (-i.bak with GNU/BSD sed) or write output to a new file. If something still looks wrong, paste a representative input line and the sed you tried; that makes it easy to spot quoting vs. regex mistakes.

You need to read up on sed and Linux/Unix regular expressions. The dot (.) has a special meaning - ie, any character. You need to preface each with an escape back slash (in a shell, two back slashes) to tell the tool to consider only a dot. Also, forward slashes are expression separators. They also need to be escaped like the dots. Try some experimentation until the output reflects your intention.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.