You can use BASH string manipulation:
f='foo-12APR2014.tar.gz'
nf="foo1-${f#*-}"
Test:
echo "$nf"
foo1-12APR2014.tar.gz
PS: If not using BASH then you can use sed:
nf=`echo "$f"|sed 's/^foo/foo1/'`
質問
i want to rename a file using mv command in shell script
now file is in the format foo-<date>.tar.gz
i want to rename it to foo1-<date>.tar.gz.
i tried, cut the foo and rename it and concatenate and all but i want to something very simple follows
mv foo*.tar.gz foo1*.tar.gz
date should be maintained only foo should be changed foo1
is it possible ? if yes how?
Thank you in advance!
解決
You can use BASH string manipulation:
f='foo-12APR2014.tar.gz'
nf="foo1-${f#*-}"
Test:
echo "$nf"
foo1-12APR2014.tar.gz
PS: If not using BASH then you can use sed:
nf=`echo "$f"|sed 's/^foo/foo1/'`