我想要复制具有不同名称的文件 我目前正在尝试这些命令,然后将它们放入我的bash脚本中。
$ set dir = /somewhere/states
$ find $dir -name "total.txt" -type f | xargs ls -1
/somewhere/states/florida/fixed.fl_Asite_ttl/somewhere/total.txt
/somewhere/states/hawaii/fixed.hi_Bsite_ttl/somewhere/total.txt
/somewhere/states/kentucky/fixed.ky_Asite_ttl/somewhere/total.txt
/somewhere/states/michigan/fixed.mi_Csite_ttl/somewhere/total.txt
/somewhere/states/texas/fixed.tx_Vsite_ttl/somewhere/total.txt
我知道我可以使用类似的东西重命名文件,但这不是我想要的:
$ find $dir -name "total.txt" -exec sh -c 'cp {} `dirname {}`/`basename {} `why.xls' \;
/somewhere/states/florida/fixed.fl_Asite_ttl/somewhere/total.txtwhy.xls
/somewhere/states/hawaii/fixed.hi_Bsite_ttl/somewhere/total.txtwhy.xls
/somewhere/states/kentucky/fixed.ky_Asite_ttl/somewhere/total.txtwhy.xls
/somewhere/states/michigan/fixed.mi_Csite_ttl/somewhere/total.txtwhy.xls
/somewhere/states/texas/fixed.tx_Vsite_ttl/somewhere/total.txtwhy.xls
我可以知道如何复制文件并将新文件放在同一个目录中吗? 以下是例子 我想将新文件命名为“修复”后面的所有内容。在“/ somewhere”之前并更改文件扩展名
/somewhere/states/florida/fixed.fl_Asite_ttl/somewhere/fl_Asite_ttl.xls
/somewhere/states/hawaii/fixed.hi_Bsite_ttl/somewhere/hi_Bsite_ttl.xls
/somewhere/states/kentucky/fixed.ky_Asite_ttl/somewhere/ky_Asite_ttl.xls
/somewhere/states/michigan/fixed.mi_Csite_ttl/somewhere/mi_Csite_ttl.xls
/somewhere/states/texas/fixed.tx_Vsite_ttl/somewhere/tx_Vsite_ttl.xls
更新: /somewhere/states/florida_fixed_ttl/fixed.fl_Asite_ttl/somewhere/total.txt
答案 0 :(得分:1)
可能不是最优雅,但这应该有效:
Range startCell = excelSheet.Cells[1,1];
Range endCell = excelSheet.Cells[3,3];
Range myCellCollection = excelSheet.Range[startCell, endCell];
如果您对输出感到满意,请删除最后一个回声,即:
find . -name total.txt | while read F ; do [[ $F =~ fixed.[^/]* ]] ; N=$(echo $BASH_REMATCH | sed s/fixed\.//) ; echo "cp $F $(dirname $F)/$N.xls" ; done
到此:
echo "cp $F $(dirname $F)/$N.xls"
请注意,如果.txt和.xls内容始终保持不变,则可以使用ln而不是cp - 一个文件,两个名称。