On Mon, 12 Nov 2018 at 14:02, srinivasan <srinivasan....@gmail.com> wrote:
> Dear Python Experts team, > > This question might be very simple for you, As am newbie to python, could > you please how to parse the below strings > > 1. Could you please do the needful in guiding me, that how can I extract > the strings under the UUID column in python code in the below output (nmcli > c show), I need to extract the UUID of "Funkloch" ie., > "1da7d068-4548-4446-bf88-a440e49db1b1" for "TYPE" wifi and device "wlp1s0" > and return this string ("1da7d068-4548-4446-bf88-a440e49db1b1") to the > robotframework? > > root:~/qa/robot_tests# nmcli c show > NAME UUID TYPE DEVICE > > Funkloch 1552 c8e1e8c0-0f25-4299-a9ae-2910cfef2ebd wifi wlp1s0 > > Wired connection 1 2a14fbe6-58a0-3b7f-b986-5d1b36a94ec0 ethernet > enp0s21f0u4 > Funkloch 1da7d068-4548-4446-bf88-a440e49db1b1 wifi -- > > Funkloch 10 f4d9ce13-aab0-4485-9929-6070ad52a196 wifi -- > > Funkloch 100 8b48a220-1754-4988-84ad-d0f83a9b4ede wifi -- > > > > 2. Similarly, As I need to verify whether the DEVICE "wlp1s0" is connected > to "Funkloch" or not? could you please help me, how can I extract the > "connected" status under "STATE column for DEVICE "wlp1s0" and CONNECTION > "Funkloch 1552" > > root:~/qa/robot_tests# nmcli dev > DEVICE TYPE STATE CONNECTION > enp0s21f0u4 ethernet connected Wired connection 1 > wlp1s0 wifi connected Funkloch 1552 > enp2s0 ethernet unavailable -- > sit0 iptunnel unmanaged -- > lo loopback unmanaged -- > > Kindly do the needful as am trying this from past two 2 days, still no > clues > > Many thanks in advance > -- > https://mail.python.org/mailman/listinfo/python-list > You can look into textfsm parser for the same, it was released specifically for this purpose of parsing CLI outputs. It should be the ideal solution for your scenario since I see some rows in your cli output which have spaces in the same column, so a hardcoded index after splitting each line on spaces will not work out. _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor