2 ms·
If you have that in a variable, which you presumably would if you're reading them one at a time, you can use "remove longest matching prefix" substitution.
by zimpenfish 6y ago
If you have that in a variable, which you presumably would if you're reading them one at a time, you can use "remove longest matching prefix" substitution.
$ i="/podcast/with/nasty'--c h a r$/and/stuff/track1.mp3"
$ echo "${i##*/}"
track1.mp3
[Edit: 'thezilch beat me too it by a couple of minutes]
- Jare 6y agoYou still get +1 for providing a pointer to the explanation while remaining clear and succinct.
- sergeykish 6y agoThis part is really cryptic, I would prefer $ function remove_longest_matching_prefix () { echo "${1##$2}"; } $ remove_longest_matching_prefix "$i" '*/' track1.mp3 awk -F/ accepts stream as in perl example