【发布时间】:2021-10-16 01:42:58
【问题描述】:
我有一个文件 test.txt:
12-09:30:09:802775 |539----> 116 Bl_LE 502450553 | <D BeginString="FIX.4.2" (...) LTPrice="13.21" 9999="bar" CheckSum="145" 12345="xxx"></D>
12-09:30:09:802775 |539----> 116 Bl_LE 502450553 | <D BeginString="FIX.4.2" (...) LTPrice="13.21" 1010="foo" CheckSum="145" 65464="xxx"></D>
我正在尝试删除以数字(9999="bar"、1010="foo" 等)开头的所有密钥/对,以使最后一行如下所示:
12-09:30:09:802775 |539----> 116 Bl_LE 502450553 | <D BeginString="FIX.4.2" (...) LTPrice="13.21" CheckSum="145"></D>
12-09:30:09:802775 |539----> 116 Bl_LE 502450553 | <D BeginString="FIX.4.2" (...) LTPrice="13.21" CheckSum="145"></D>
我尝试使用带有“tr”命令的单行命令,但不知道如何将其组合在一起:
$$ perl -ne 'tr/(\d+="[^"]*")//g' test.txt
Bareword found where operator expected at -e line 1, near "tr/(\d+="[^"]*")//g"
syntax error at -e line 1, next token ???
Execution of -e aborted due to compilation errors.
关于如何实现这一目标的任何想法?
【问题讨论】:
-
tr///用于映射单个字符替换。正如下面的答案所示,您希望s///使用正则表达式。
标签: regex perl regex-negation