Perl 仅在模式/关键字后返回字符串
我有一个列表(数组中的值),如下所示:Perl 仅在模式/关键字后返回字符串,perl,sed,grep,Perl,Sed,Grep,我有一个列表(数组中的值),如下所示: order_reply1={order_tag=1286955 order_reply2={order_tag=1286956 order_reply3={order_tag=1286957 order_reply4={order_tag=1286958 order_reply5={order_tag=1286959 order_reply6={order_tag=1286960 order_reply7={order_tag=1286961 由此,我想
order_reply1={order_tag=1286955
order_reply2={order_tag=1286956
order_reply3={order_tag=1286957
order_reply4={order_tag=1286958
order_reply5={order_tag=1286959
order_reply6={order_tag=1286960
order_reply7={order_tag=1286961
由此,我想返回order_tag=之后的值。我该怎么做呢?我不想在这个“关键字”之前做任何事情。原因是,我希望返回的标记继续使用这些引用查询数据库。grep是正确的工具:
sed 's/.*order_tag=//' YourFile
# -> 1286961
sed 's/.*\(order_tag=\)/\1/' YourFile
# -> order_tag=1286961
kent$ grep -Po '.*order_tag=\K.*' f
1286955
1286956
1286957
1286958
1286959
1286960
1286961
在出门的路上,这里有另一种方法,在=字符上使用split:
perl -e '$o=q(order_reply1={order_tag=1286955); $n=(split /=/, $o)[-1]; print "o= $o\n"'
在Perl中有几种方法可以实现这一点,您已经尝试了哪些代码?你在哪里卡住了?谢谢这是我需要的!
perl -e '$o=q(order_reply1={order_tag=1286955); $n=(split /=/, $o)[-1]; print "o= $o\n"'