Linux 从文本行内剪切字段

Linux cut fields from inside text line

我想从这行中删除 ;XXm m:;XXm:

Xmorg.camunda.bpm.engine.context          ;XXm m:;XXm ENGINE-XXXXX Exception while
Xma.ExceptionLoggingFilter    ;XXm m:;XXm Uncaught exception thrown
Xmb.ExceptionHandlerController;XXm m:;XXm handle exception

这会截断整行:

cut -d" " -f2,3 

我想要的结果是:

Xmorg.camunda.bpm.engine.context          ENGINE-XXXXX Exception while
Xma.ExceptionLoggingFilter    Uncaught exception thrown
Xmb.ExceptionHandlerController handle exception

Xmorg.camunda.bpm.engine.context ENGINE-XXXXX Exception while 
Xma.ExceptionLoggingFilter Uncaught exception thrown
Xmb.ExceptionHandlerController handle exception

我不明白它真的有效:

[Alex@Normandy templates]$ echo "Xmorg.camunda.bpm.engine.context ;XXm m:;XXm ENGINE-XXXXX BPMN Stack Trace:" | cut -d" " -f2,3 
;XXm m:;XXm

如果你想要反转,你可以使用 Python 比如:


>>> x="Xmorg.camunda.bpm.engine.context ;XXm m:;XXm ENGINE-XXXXX BPMN Stack Trace:"
>>> x_splited=x.split()
>>> " ".join(x_splited[:1]+x_splited[3:])
'Xmorg.camunda.bpm.engine.context ENGINE-XXXXX BPMN Stack Trace:'

好的,你误导了“剪切”这个词。

cut -d" " -f1,4

这将从字符串中准确提取第一项和第四项

I want reverse result :), I want to cut ;XXm m:;XXm from this fil

cut --complement -d" " -f2,3 

cut -d" " -f1,4-

了解正则表达式。

sed 's/;XXm m:;XXm//'