baris35
September 10, 2021, 10:04pm
1
Hello,
brew install rename
does not work in terminal due to Mac version incompatibility issue.
I have hundreds of filenames starting with output_*.html
and I need to trim output_
section
I have found some tutorials but do not exactly match to my case.
ls * | mv output_\\
does not work.
Could you please let me know if there is an easy way to accomplish this process?
Extra effort:
When I go in deeper, some says " homebrew
should also be installed".
Below code does not install homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
It asks me to run:
/usr/local/bin/brew update --force --quiet
Which returns to:
Failed during: /usr/local/bin/brew update --force --quiet
And asks me to run below commands:
git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask fetch --unshallow
I suppose it will take a bit longer to be completed. I will let you know when it is done.
Result:
At the end, I run again brew install rename
It updated homebrew
and installation of the command rename
has been completed..
Thank you
Boris
Neo
September 11, 2021, 3:17am
2
Seems to work fine on my mac:
$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.15.7
BuildVersion: 19H1217
$ brew install rename
OK
$ rename
Usage:
rename [switches|transforms] [files]
Switches:
--man (read the full manual)
-0/--null (when reading from STDIN)
-f/--force or -i/--interactive (proceed or prompt when overwriting)
-g/--glob (expand "*" etc. in filenames, useful in Windows™ CMD.EXE)
-k/--backwards/--reverse-order
-l/--symlink or -L/--hardlink
-M/--use=*Module*
-n/--just-print/--dry-run
-N/--counter-format
-p/--mkpath/--make-dirs
--stdin/--no-stdin
-t/--sort-time
-T/--transcode=*encoding*
-v/--verbose
Transforms, applied sequentially:
-a/--append=*str*
-A/--prepend=*str*
-c/--lower-case
-C/--upper-case
-d/--delete=*str*
-D/--delete-all=*str*
-e/--expr=*code*
-P/--pipe=*cmd*
-s/--subst *from* *to*
-S/--subst-all *from* *to*
-x/--remove-extension
-X/--keep-extension
-z/--sanitize
--camelcase --urlesc --nows --rews --noctrl --nometa --trim (see manual)
1 Like
baris35
September 11, 2021, 7:57am
3
Thank you Neo,
homebrew
installation was incomplete.
Kind regards
Boris
1 Like
Azhrei
September 11, 2021, 8:14pm
4
FYI, that kind of renaming is easy to do with a loop:
for i in output_*.html
do
mv "$i" "${i%output_}"
done
For more complicated stuff, a program like rename
is a good choice.
2 Likes
The %
trims from the end .
I think you mean #
i.e. from the beginning .
for i in output_*.html
do
mv "$i" "${i#output_}"
done
2 Likes
baris35
September 15, 2021, 9:22am
6
Thank you @MadeInGermany ,
Works as expected with mv
command.
root@WDMyCloud # ls
output_1.html out_2.html s.sh
root@WDMyCloud # ./s.sh
root@WDMyCloud # ls
1.html 2.html s.sh
Kind regards
Boris