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)
- 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
- wget download a file to a directory in Linux/Unix - June 4, 2018
- GIT: How to compare two GIT branches? - June 3, 2018
- Online training on Linux Bash shell scripting - February 8, 2018