bash - Remove file's substring to index in terminal -


i have file list. following pattern : _000n_name.png (with n file number)

in terminal (linux or mac os) possible delete '000n' in single command files ?

sed can job:

sed 's/^_[0-9]*\(_.*\)$/_\1/' 

if want strip underscores (before & after numbers) also:

sed 's/^_[0-9]*_\(.*\)$/\1/' 

full script:

while read f;     mv "$f" $(echo "$f"|sed 's#^.*_[0-9]*_\(.*\)$#\1#') done < <(find . -name "_0*_name.png") 

Comments