Perl 命令的行为不符合预期?
我有一个包含以下内容的文件:
[TEMP.s_m_update_BUS_spec]
$$SRC_STAT_RA=WHG_STATUS_SITEENTSEQCHAIN_20110901094550.dat
$InputFile_RA_SPE=/edwload/rqt/workingdir/status_spe/WHG_STATUS_SITEENTSEQCHAIN_20110901094550.dat
[TEMP.s_m_upd_salions_rqthk]
$$SRC_STAT_RN=WHG_STATUS_SITEENTSEQCHAIN_20110901094550
$InputFile_RN_RQT=/edwload/rqt/workingdir/restriction/WHG_STATUS_SITEENTSEQCHAIN_20110901094550.dat
我使用下面的 perl 命令将 [TEMP.s_m_upd_salions_rqthk]
部分中的 WHG_STATUS_SITEENTSEQCHAIN_20110901094550
替换为 WHG_STATUS_SITEENTSEQCHAIN_20110901999999.dat
>但不知怎的,它没有给我预期的结果。甚至[TEMP.s_m_update_BUS_spec]
部分下的WHG_STATUS_SITEENTSEQCHAIN_20110901094550
也被替换。
perl -p -i -e "s|\$\$SRC_STAT_RN=.*|\$\$SRC_STAT_RN=WHG_STATUS_SITEENTSEQCHAIN_20110901999999.dat|g;s|\$InputFile_RN_RQT=\/edwload\/rqt\/workingdir\/restriction\/.*|\$InputFile_RN_RQT=\/edwload\/rqt\/workingdir\/restriction\/WHG_STATUS_SITEENTSEQCHAIN_20110901999999.dat|g" Input_File
请让我知道上面命令中所需的修改。相同的替代命令与 SED 命令一起工作正常。但我想使用perl。
I have a file with below contents:
[TEMP.s_m_update_BUS_spec]
$SRC_STAT_RA=WHG_STATUS_SITEENTSEQCHAIN_20110901094550.dat
$InputFile_RA_SPE=/edwload/rqt/workingdir/status_spe/WHG_STATUS_SITEENTSEQCHAIN_20110901094550.dat
[TEMP.s_m_upd_salions_rqthk]
$SRC_STAT_RN=WHG_STATUS_SITEENTSEQCHAIN_20110901094550
$InputFile_RN_RQT=/edwload/rqt/workingdir/restriction/WHG_STATUS_SITEENTSEQCHAIN_20110901094550.dat
I am using below perl command to just replace WHG_STATUS_SITEENTSEQCHAIN_20110901094550
with WHG_STATUS_SITEENTSEQCHAIN_20110901999999.dat
in the section [TEMP.s_m_upd_salions_rqthk]
But somehow its not giving me expected result. Even the WHG_STATUS_SITEENTSEQCHAIN_20110901094550
under section [TEMP.s_m_update_BUS_spec]
is getting replaced.
perl -p -i -e "s|\$\$SRC_STAT_RN=.*|\$\$SRC_STAT_RN=WHG_STATUS_SITEENTSEQCHAIN_20110901999999.dat|g;s|\$InputFile_RN_RQT=\/edwload\/rqt\/workingdir\/restriction\/.*|\$InputFile_RN_RQT=\/edwload\/rqt\/workingdir\/restriction\/WHG_STATUS_SITEENTSEQCHAIN_20110901999999.dat|g" Input_File
Please let me know the modifications required in command above.Same subsitute commands works fine with SED command. But i wud want to use perl.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您运行的程序
有相当多的
$
应该被转义,但没有。如果使用单引号而不是双引号会更简单。您可能正在尝试:The program you run is
There are a fair number of
$
that should be escaped but aren't. It would be simpler if you used single quotes instead of double quotes. You were probably trying for:究竟是什么没有按照您的要求工作?在我的机器上,运行 Perl 代码后,该文件如下所示:
这不是您所期望的吗?
编辑
尝试将命令修改为:
并查看结果是否符合预期:
What exactly is not working as you want? On my machine, after running your perl code, the file looks like:
Ain't this what you expected?
Edit
Try modifying your command to:
and see if the result is as expected: