我有一个文件 ../reports/[2015-10-01]-[2015-10-07]。它是一个大文件,所以当我尝试使用“拆分”命令拆分它时,出现错误,因为 bash 将 [] 视为字符类。 我的脚本:
hdfs='hadoop fs'
startDate=$1
endDate=$2
reportPath="/reports/weeklyReport/[${startDate}]-[${endDate}]"
tmpWorkingDirectory="/tmp/weeklyReport"
filePrefix="WeeklyReport[${startDate}]-[${endDate}]-Part-"
if [ -d $tmpWorkingDirectory ]; then
rm -rf $tmpWorkingDirectory
fi
mkdir $tmpWorkingDirectory
$hdfs -getmerge $reportPath $tmpWorkingDirectory/report.txt
split -d -C 10240000 $tmpWorkingDirectory/report.txt $filePrefix
.....
我收到错误::
getmerge: Illegal file pattern: Illegal character range near index 6 [2015-10-01]-[2015-10-07]
我尝试将转义字符“\”与“[”一起使用,但它仍然无法正常工作。 请建议我如何阅读此文件。
最佳答案
...那这个呢? $hdfs -getmerge "$reportPath""$tmpWorkingDirectory/report.txt"
关于bash - 如何使用 bash 命令读取名称中包含 '[' 和 ']' 的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33079059/