我有一个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.
有什么好主意吗?
您可以使用:
perl -pe 's/h+d+="[^"]*"//g' test.txt
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>
RexEx细节:
h+
:匹配1个或多个空白d+
:匹配1+位=
:匹配=
"[^"]*"
:匹配引号值