shell脚本修改文中日期

shell脚本修改文中日期

INSERT INTO SQOOP_SESSIONS VALUES('job_test','incremental.last.value','2020-01-13 00:35:48','SqoopOptions')

#define version "0.0.1 2020-01-13 00:35:48"
now=`date +"%Y-%m-%d %H:%M:%S"`
echo $now

# 正则表达式
re="[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\} [0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}"

# 修改目标1
objTest="\(^INSERT INTO SQOOP_SESSIONS VALUES('job_test','incremental.last.value','\)"$re"\(','SqoopOptions')\)"

# 修改目标2
objTest2="\(^\#define version \"0.0.1 \)"$re"\(\"\)"

sed -i -e "s/$objTest2/\1$now\2/" test.txt

sed -i -e "s/$objTest/\1$now\2/"  test.txt

你可能感兴趣的:(Linux,命令及工具,shell)