mahmood
mahmood

Reputation: 24705

Issue on text processing using cut command

I have a text file which has a format like this

 data: [      142] CPU 10 <v:0xffffffff3d4331bc> <p:0x004d38331bc> Nrml Read 4 bytes  0x2a72c08

I want to extract the two hex values in front of v: and p:. As a result I want an output like this

 ffffffff3d4331bc 004d38331bc

Problem is that the delimited character doesn't work properly with cut command. Right now I use

 cut -d: -f3 data2.txt

But the output is 0xffffffff3d4331bc> <p

I also don't want the 0x header.

Upvotes: 0

Views: 73

Answers (1)

jaypal singh
jaypal singh

Reputation: 77085

 grep -oP '<[vp]:0x[0-9a-z]+' data.txt | sed 's/.\{5\}//'

As @chepner suggested in the comments, you can use a positive look-behind assertion which will reduce the answer to

 grep -oP '(?<=<[vp]:0x)[0-9a-z]+' data.txt | sed 'N;s/\n/ /'

Upvotes: 3

Related Questions