michealAtmi
michealAtmi

Reputation: 1042

Linux cut fields from inside text line

I want to cut ;XXm m:;XXm from this lines:

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

This cuts whole line:

cut -d" " -f2,3 

The result I want is:

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

or

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

Upvotes: 0

Views: 83

Answers (3)

KamilCuk
KamilCuk

Reputation: 141040

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

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

or

cut -d" " -f1,4-

Learn about regexes.

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

Upvotes: 1

luca.vercelli
luca.vercelli

Reputation: 1038

Ok, you used the word "cut" in a misleading way.

cut -d" " -f1,4

This will extract exactly the first and fourth item from string

Upvotes: 0

Alex Baranowski
Alex Baranowski

Reputation: 1084

I don't get it it actually works:

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

If you want reverse you can use Python like:


>>> 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:'

Upvotes: 0

Related Questions