From time to time I have to write some small bash scripts (since writing them in Perl/Ruby/Python/… would simply be an overkill). Most of the time this involves some kind of directory-listing-parsing which is quite simple using find, grep and sed.
Since I couldn’t sleep tonight I decided to work through and there I needed a script that checks if a folder holding a .mp4 file also holds a .tgz file with the same basename. Not being really good at bash scripting googling helped me quite a lot with this nice tutorial site: Bash Scripting FAQ on splike.com
But there was only described a way to get the extension of a file. Guessing that getting the other part of the file shouldn’t be all that different I opened the ABS and checked the string operations reference. ${string%.*} should normally do what I want. So here is the small script. Hopefullly it will be useful for someone else :)
#!/bin/bash for video in `find . -name '*.mp4' `; do basename=${video%.*} if [ ! -f "${basename}.tgz" ]; then echo $basename fi done
Do you want to give me feedback about this article in private? Please send it to comments@zerokspot.com.
Alternatively, this website also supports Webmentions. If you write a post on a blog that supports this technique, I should get notified about your link π