比如下面csv目录中的文件lf-orders-2018-11-20(1700).csvlf-orders-2018-11-20 17002.csv文件名中带有空格,和夹杂着中英文圆括号,需要将他们替换为下划线_生成下面的:lf-orders-2018-11-20_1700_.csvlf-orders-2018-11-20_17002.csvSAVEIFS=$IFSIFS=$'\n'for file in `ls csv | grep .csv`do
newfile=`echo ${file} | sed 's/ /_/g'| sed 's/(/_/g'| sed 's/)/_/g'` # echo $newfile
mv csv/$file csv/$newfiledone# revert IFSIFS=$SAVEIFS我现在已经有了上面的脚本,不太好用,会报mv: cannot stat 'csv/lf-orders-2018-11-20 17002 .csv'$'\n''lf-orders-2018-11-20'$'\357\274\210''1700).csv': No such file or directory求更简洁的写法,谢谢!
- 1 回答
- 0 关注
- 465 浏览
添加回答
举报
0/150
提交
取消