#!/usr/bin/env fish # syntax: moov files... regex target set regex $argv[-2] set target $argv[-1] set files $argv[1..-3] for file in $files set matches (string match -ar "$regex" "$file") set target_path "$target" set counter 0 for match in $matches set target_path (string replace -a '$'"$counter" "$match" "$target_path") set counter (math $counter + 1) end mv "$file" "$target_path" end