在shell脚本中分割并重命名分割后的文件 [英] Split and rename the splitted files in shell script
本文介绍了在shell脚本中分割并重命名分割后的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下命令吐出文件
i used below command to spit the file
split -l 100 date.csv date.csv
文件拆分如下
date.csvaa
date.csvab
date.csvac
date.csvad
date.csvae
我要重命名以下文件.
date_1.csv
date_2.csv
date_3.csv
date_4.csv
date_5.csv
请帮助
推荐答案
有很多方法可以解决此问题.其他答案提供了仅通过传递给 split
的参数来执行此操作的方法-但是ubuntu 12.04上的split版本似乎不支持这些答案中使用的参数.
There are many ways of approaching this. Other answers provide a way to do it just with arguments passed to split
- however the version of split on ubuntu 12.04 don't appear to support the arguments used in those answers.
这里是一个.这将拆分文件,并使用 split
上的默认选项为文件名加上 x
前缀.然后,它将按顺序列出文件,并根据需要将其重命名.
Here is one. This splits the files and uses the default option on split
to prefix the file names with an x
. It then lists the files in order and renames them as required.
split -l 100 date.csv
i=1
for x in `ls x* | sort`
do
mv $x date_$i.csv
i=$(($i+1))
done
这篇关于在shell脚本中分割并重命名分割后的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文