Renaming files with Bash, removing prefix and suffix
Another approach, for fun, using regular expressions: regex=’prefix – (.*) – suffix.txt’ for f in *.txt; do [[ $f =~ $regex ]] && mv “$f” “${BASH_REMATCH[1]}.txt” done Actually, using the simple pattern ‘*.txt’ here has two problems: It’s too broad; you may need to apply the regex to a lot of non-matching files. If there … Read more