Doing some reading here and here I found this solution to replace two underscores in filenames with only one using bash:
for file in *; do
f=${file//__/_}
echo $f
done;
However how do I most easily expand this expression to replace an arbitrary number of underscores with only one?
shopt -s extglobif it's not already enabled) you could usef="${f//+(_)/_}". E.g. for the file "test_____something__else.txt",for f in test_*; do f="${f//+(_)/_}"; echo $f; donereturnstest_something_else.txt. More details here: askubuntu.com/a/889746