[英]How to substitute dates in Perl?
perl -pi.back -e 's/2013/07/31-05:54:14/2014/07/31-00:00:00/g;' /tmp/ranjan/replace.SEL
I'm using the above one liner to replace the date from 2013/07/31-05:54:14
to 2014/07/31-00:00:00
. 我使用上面的一个班轮来代替
2013/07/31-05:54:14
到2014/07/31-00:00:00
。 But I'm unable to do it. 但我无法做到。 I'm able to find only substitution for string not for numbers which are in the above format .
我只能找到字符串的替换而不是上述格式的数字。 please help me out.
请帮帮我。
Use an alternative delimiter : 使用替代分隔符 :
s{find}{replace}g;
or 要么
s#find#replace#g;
Otherwise you'd have to escape all the /
. 否则你必须逃脱所有
/
。
Perl thinks that the forward slashes in your dates are actually part of the substitution statement s///g
, so you can either escape the slashes in your dates or use a different delimiter for your substitution Perl认为你日期中的正斜杠实际上是替换语句
s///g
,所以你可以转义日期中的斜杠或使用不同的分隔符替换
perl -pi.back -e 's/2013\/07\/31-05:54:14/2014\/07\/31-00:00:00/g;'
or more readable: 或更具可读性:
perl -pi.back -e 's#2013/07/31-05:54:14#2014/07/31-00:00:00#g;'
You have to change your delimeter or you have properly escape your regexp strings. 您必须更改分隔符,或者已正确转义正则表达式字符串。
The dilmeter could be anything non printable, i like to use !. 稀释剂可以是任何不可打印的,我喜欢使用!
like this: 像这样:
s!2013/07/31-05:54:14!2014/07/31-00:00:00!g;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.