1

I'm trying to process an m3u playlist file structured as is:

#EXTM3U
#EXTING:193,Song name
/path/to/the/song.mp3
#EXTING:201,Another song
/somewhere/in/a directory/song2.mp3

The aim is, for every line containing a path, remove the path and keep only filename and extension. For example, the file above would become:

#EXTM3U
#EXTING:193,Song name
song.mp3
#EXTING:201,Another song
song2.mp3

I tried with awk several variations, the closest I could get was this one:

awk '{if ((NR % 2 == 1) && (NR != 1)){print "$(basename $0)"}else{print}}' playlist.m3u

The if/else structure is ok, only the "print basename" thing doesn't work, and I have to admit that shell is not my strong suit ;)

Can someone help?

Thanks a lot!

  • seems, he wants the # line also.. awk -F/ '!/^#/{$0=$NF}1' playlist.m3u – Kamaraj Dec 13 '16 at 0:15
2
awk -F/ '!/^#/{$0=$NF}1' playlist.m3u

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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