Re: Bash substrings – just can’t figure it out…

Johnny Rosenberg gurus.knugum at gmail.com
Wed Feb 1 22:04:39 UTC 2012


2012/2/1 Nils Kassube <kassube at gmx.net>:
> Johnny Rosenberg wrote:
>> Slightly off topic:
>> I am still a bit proud over that I figured out a way to get the album
>> artist out of the path to the flac file. The path looks something
>> like this:
>> Folder="/some/subfolders/and/some/more/subfolders/then/artist/album"
>>
>> The artist is always the last but one level of the path, but the
>> total number of levels may vary.
>> So here is my one-liner, using awk:
>> Artist=$(echo "$Folder" | awk -F "/" '{print $((NF-1))}')
>>
>> Took me a while to figure out how to use $NF in the print statement.
>> Of course I have no doubts that there is a better solution, so if you
>> have one, please share. I love to learn! Still a newbie though.
>
> How about this?
>
> Artist=$(basename $(dirname "$Folder"))

Oh… yes, of course! Didn't think of that… :D


Kind regards

Johnny Rosenberg
ジョニー・ローゼンバーグ

>
>
> Nils
>
> --
> ubuntu-users mailing list
> ubuntu-users at lists.ubuntu.com
> Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users




More information about the ubuntu-users mailing list