With perl's rename
:
rename 's/(PMC|\.pdf)//g' *pdf.txt
Demo :
$ ls *txt
PMC21375.pdf.txt
$ rename -n 's/(PMC|\.pdf)//g' *txt
PMC21375.pdf.txt -> 21375.txt
from the shell
prompt. It's very useful, you can put some perl code like I does in a substitution.
You can remove the -n
(dry-run mode switch) when your tests become valids.
There are other tools with the same name which may or may not be able to do this, so be careful.
If you run the following command (linux
)
$ file $(readlink -f $(type -p rename))
and you have a result like
.../rename: Perl script, ASCII text executable
then this seems to be the right tool =)
If not, to make it the default (usually already the case) on Debian
and derivative like Ubuntu
:
$ sudo update-alternatives --set rename /path/to/rename
(replace /path/to/rename
to the path of your perl's rename
command.
Last but not least, this tool was originally written by Larry Wall, the Perl's dad.
I would use the mcp
tool from the mmv
("multiple move") package for that:
mcp '/home/user/*/*/Load.bdf' '#1_#2_Load.bdf'
The #1
, #2
etc. in the second string will be replaced by the contents of the corresponding 1st, 2nd etc. wildcard from the first string. Note that the path is in single quotes so that the wildcards are interpreted by mcp
, not by the shell.
With the command shown, the files will be copied to the current directory. If you replace mcp
with mmv
, the files will be moved instead.
Best Answer
Assuming your shell is zsh, put
autoload -U zmv
in your~/.zshrc
, and run