开发者

Copy a whole bunch of files with their names being changed a little bit using shell script

I have a very large number of files with very similar names: row1col1.txt, row1col2.txt, row1col3.txt, row1col4.txt......

I'd like to make copies of them all and change the names to row2col1.txt, row2col2.txt, row2col3,txt, row2col4.txt......

Using the开发者_如何学编程 cp command in shell script, how can I do it efficiently?


How are you going to generate the file names? How are you going to specify the substitution?

One possibility is:

ls row1col*.txt |
sed 's/row1\(.*\)/cp & row2\1/' |
sh -x

This uses ls to generate the list of names, and sed to generate a cp command for each named file, and pipes that to sh so that the copy operations occur. Don't run it to sh until you are confident that the rest is right.


If you use the program mcp contained in the packet mmv, you can do that like this:

mcp row1\* row2\#1
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜