mardi 21 juillet 2015

How can I find the match string in pattern(AWK)?

I have a text file with the pattern starting '-- Host' and ending ';', and this pattern occurs so many times in the file.

-- Host (first) Sid (queen1)

-- prince princess#/king 1/1

;

-- Host (first) Sid (queen2)

-- prince princess#/king 2/2

;

-- Host (first) Sid (queen3)

-- dir princess#/king 3/3

;

Below is my desired result.

queen1 1/1

queen2 2/2

queen3 3/3

With AWK, I think I can specify the block including this patten like below. However, I got error in putting the second pattern in pattern. Can you help me accomplish this requirement?

BEGIN { }

/-- Host/,/;/ { /prince/ { print $3 } }

END

Aucun commentaire:

Enregistrer un commentaire