regex - How can I isolate specific string patterns from this body of text -
i have following file: 2013-07-17_19-12-42.dcrec
how can search , isolate following string pattern in file:
new name client 0, keyid = 000000, ip = 000.000.000.000 : somename
the client # number, keyid numerical value (there not set length client # or keyid), ip normal ipv4 address , somename username (the username can include special characters such #, ^, @, spaces, etc). looks string 'closed' '^bvs'. here example of 2 of strings (see screenshots)
there can number of these strings in each file(s). if search , list instances of these strings in file(s) great. im not grep, etc @ moment or else able on own. appreciated, thanks!
$> strings 2013-07-17_19-12-42.dcrec | grep -o -p "new name client [0-9]+, keyid = [0-9]+, ip = [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3} : [^\ ]+" new name client 7, keyid = 562830, ip = 91.193.208.105 : sobieski new name client 8, keyid = 255344, ip = 63.153.210.124 : cultist new name client 11, keyid = 5061431, ip = 116.240.255.94 : sammy new name client 12, keyid = 5061453, ip = 196.20.195.114 : dirk new name client 13, keyid = 4278381, ip = 188.110.185.183 : csto new name client 14, keyid = 369397, ip = 81.110.45.165 : general new name client 16, keyid = 5061651, ip = 85.4.29.162 : thatsuseless new name client 17, keyid = 5061688, ip = 90.213.51.77 : newplayer new name client 18, keyid = 4905930, ip = 174.109.181.108 : solo new name client 19, keyid = 5061695, ip = 85.4.236.70 : quizzman new name client 21, keyid = 2745089, ip = 95.128.68.231 : newplayer new name client 22, keyid = 5061536, ip = 195.91.236.65 : powerfucker new name client 24, keyid = 5061698, ip = 86.121.66.142 : thedoctor new name client 26, keyid = 5061585, ip = 5.69.250.33 : hydrogen
explanations:
- if input file in binary format processed
strings
retrieve text; - the client # number :
[0-9]+
- the keyid numerical value :
[0-9]+
- the ip normal ipv4 address :
[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}
- somename username (the username can include special characters such #, ^, @, spaces, etc) :
[^\ ]+
means "no spaces"
seems enough first time. yep, these regexps improved.
upd: actually, looks better .*
regex last field (somename)
Comments
Post a Comment