Sep-24-2018, 12:20 PM
Hi Team,
How do I extract specific pattern in below code. As I have tried to get expected output through regex and use Python Dictionary in order to fetch it through values but unable to get it.
rlinux57
How do I extract specific pattern in below code. As I have tried to get expected output through regex and use Python Dictionary in order to fetch it through values but unable to get it.
#!/usr/bin/python import re line = '''CLIENT LIST Updated,Wed Sep 19 10:22:48 2018 Common Name,Real Address,Bytes Received,Bytes Sent,Connected Since dell,110.23.15.12:50731,14298,15058,Wed Sep 19 09:59:23 2018 sony,110.23.15.12:48050,93394,98996,Wed Sep 19 10:21:44 2018 ROUTING TABLE Virtual Address,Common Name,Real Address,Last Ref 192.168.250.114,dell,110.23.15.12:48050,Wed Sep 19 10:22:46 2018 192.168.250.50,sony,110.23.15.12:50731,Wed Sep 19 09:59:25 2018 GLOBAL STATS Max bcast/mcast queue length,0 END''' dict = re.findall(r'^\d(.*?,\s*(.*?),)', line, re.M) if dict: print "Users Connected", dict else: print "Nothing found!!"Output:
Output:Users Connected: [('92.168.250.114,dell,', 'dell'), ('92.168.250.50,sony,', 'sony')]
Expected Output:Output:Users Connected: dell, sony and so on...
Regards,rlinux57