Music Library One-Liner

I'm learning more about powerful tools like sed and awk while taking a break from my task management app project. One-liners are great for many reasons -- they're easy to stick in your .bashrc or .zshrc file as aliases or to incorporate into functions.

This particular one-liner simply traverses a music directory, organized as Artist/Album/Songs, and dumps it out in a pretty list.

cd ~/Music && find . \! -name ".*" | sed -Ee 's/[0-9]{2} //g' -Ee 's/\.(m4a|mp3)$//g' | awk -F/ 'NF > 0 {for (i=2;i<NF;i++) { printf "    " } print $NF}'

Here's a snippet of what the output looks like:

...
Phoenix
    Wolfgang Amadeus Phoenix
        Lisztomania
        1901
        Fences
        Love Like A Sunset Part I
        Love Like A Sunset Part II
        Lasso
        Rome
        Countdown
        Girlfriend
        Armistice
R.E.M.
    Reveal
        The Lifting
        I've Been High
        All The Way To Reno (You're Gonna Be A Star)
...

This written work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

blog comments powered by Disqus