sed 脚本分隔符引起的问题unknown option to `s'
执行脚本sed:
source ../../conf.properties
target_dir=data_process_$DATE
current_date=$(date +%Y/%m/%d/%H)
echo $current_date
rm -rf $target_dir > /dev/null 2>&1
mkdir $target_dir
# Generate the ql from the merge_table directory
for ql in `ls merge_table | grep ql`
do
sed "s/%CHINADAASREDUCETASKS%/$MAPRED_REDUCE_TASKS/g" merge_table/$ql > $target_dir/$ql
sed -i "s/%CHINDAASDATE%/$DATE/g" $target_dir/$ql
sed -i "s/%current_date%/$current_date/g" $target_dir/$ql
done
报错如下:
sed: -e expression #1, char 25: unknown option to `s'
原因:
因为路径里面包含有“/”作为分隔符,这会和sed的替换操作的分隔符“/”引起混淆;所以改为#,只要不使用“/”做分隔符就可以解决这个问题。