Want to copy the files which has 63 in its name , change it to 64 and copy it in the same directory. How can i do it.
要复制名称中包含63的文件,将其更改为64并将其复制到同一目录中。我该怎么做。
Tried using awk,sed not working.
尝试使用awk,sed不工作。
ls *63*
For example if the file is test63.txt
it should get copied to test64.txt
in the same directory . if the file is 63test.txt
it should get copied to 64text.txt
例如,如果文件是test63.txt,它应该被复制到同一目录中的test64.txt。如果文件是63test.txt,它应该被复制到64text.txt
2 个解决方案
#1
1
What about something like this:
这样的事情怎么样:
for f in *63*; do newname=`echo $f | sed 's/63/64/'`; cp $f $newname; done
Broken down into multiple lines:
细分为多行:
for f in *63*; do
newname=`echo $f | sed 's/63/64/'`
cp $f $newname
done
#2
1
A generalized bash
solution with a specifiable number that is incremented by 1:
一个广义的bash解决方案,其可指定的数字递增1:
n=63
for f in *"$n"*; do
cp "$f" "${f/$n/$((n+1))}"
done
#1
1
What about something like this:
这样的事情怎么样:
for f in *63*; do newname=`echo $f | sed 's/63/64/'`; cp $f $newname; done
Broken down into multiple lines:
细分为多行:
for f in *63*; do
newname=`echo $f | sed 's/63/64/'`
cp $f $newname
done
#2
1
A generalized bash
solution with a specifiable number that is incremented by 1:
一个广义的bash解决方案,其可指定的数字递增1:
n=63
for f in *"$n"*; do
cp "$f" "${f/$n/$((n+1))}"
done