I think I'd solve it by something like: pkgs=$(ls /var/log/packages/*_SBo | sed 's/-[^-]*-[^-]*-[^-]*$//' | sed 's/.*\///') removepkg $pkgs sboinstall $pkgs ... of course, I'm a bit biased since I'm the current maintainer of sbotools.