在Unix脚本中用字符串变量连接字符串

时间:2019-01-24 23:55:58

标签: shell unix

我必须形成一个注释标签,以将其附加到我已经创建的目标XML文件中。尝试将从XML文件提取的值以及之间的一些字符串连接在一起时,某些字符串/变量值未按预期填充。

echo "<!--Claims"," state ${STATE}"," ${env}"," ${paid_start}"," ${paid_stop}"," ${incur_start}"," ${incur_stop} -->"

incur_start=`grep "<ProfessionalClaim" test.xml \
| sed -n '1p;$p' \
| awk 'NR==1 {match($0, "claimStartDate=\"([^\"]+)\"", start); print "incur_start " start[1]}'`

incur_stop=`grep "<ProfessionalClaim" test.xml \
| sed -n '1p;$p' \
| awk 'NR==2 {match($0, "claimEndDate=\"([^\"]+)\"", end); print "incur_stop " end[1]}'`

paid_start=`grep "<ProfessionalClaim" test.xml \
| sed -n '1p;$p' \
| awk 'NR==1 {match($0, "claimProcessedDateTime=\"([^\"]+)\"", start); print "paid_start " start[1]}'|cut -c1-19`

paid_stop=`grep "<ProfessionalClaim" test.xml \
| sed -n '1p;$p' \
| awk 'NR==2 {match($0, "claimProcessedDateTime=\"([^\"]+)\"", end); print "paid_stop " end[1]}'|cut -c1-18`

v_state="$(grep "STATE=" /root/temp.prm)"
STATE=`echo $v_state | cut -d "=" -f2`
env="env t"

预期结果:

<!-- Claims, state CA, env t, paid_start 20180409, paid_stop 20180430, incur_start 2018-04-02, incur_stop 2018-04-17 -->

实际结果:

,env t, paid_start 20180409, paid_stop 20180430, incur_start 2018-04-02, incur_stop 2018-04-17 -->

0 个答案:

没有答案