This is bit tricky and the solution I got is below script
for i in $(ls | grep ‘[0-9]’)
eval mv $i $(echo $i | sed ‘s/[0-9]/*/g’)
Some of the issues I faced are
1)In sed I tried to replace numbers with just * which created an issue
2)In sed I tried to replace numbers with * which is still not working.
So I tried to use eval to get this solution. I advantage of eval is that it will try to evaluate a shell code on the fly.
ls | grep [0-9] will give you the files which contain a single number in it’s filename, this output is feed in to for loop and each value is read in to i variable.
sed ‘s/[0-9]/*/g’ Will search for a number in the filename and replace it with *.
eval command will convert mv $filename $(echo $i | sed ‘s/[0-9]/*/g’) to mv file1name file*name
Hope this helps.
Latest posts by Surendra Anne (see all)
- Docker: How to copy files to/from docker container - June 30, 2020
Anisble: ERROR! unexpected parameter type in action:
Fix- June 29, 2020
- FREE: JOIN OUR DEVOPS TELEGRAM GROUPS - August 2, 2019
- Review: Whizlabs Practice Tests for AWS Certified Solutions Architect Professional (CSAP) - August 27, 2018
- How to use ohai/chef-shell to get node attributes - July 19, 2018