How to parse a multiline string

Beginner programmer

I am running a CLI command then doing a split. unfortunately the output is a constent string
example

03 = {str} 'ONT  PROFILE   PROVISIONED  PRIMARY  PROTECT  REG  SERIAL   SUBSCRIBER                                            MAC   BATTERY  VENDOR  DEVICE  STATS    UPGRADE  TIMEOUT   RETURN             THRESH  THRESH  THRESH  THRESH  PWR FE  PWR FE  SDBER  POWER   
04 = {str} 'ID   ID        PON          PON      PON      ID   NUMBER   ID          LOCATION  DESCRIPTION                     ADDR  PRESENT  ID      TYPE    GROUP    CLASS    PROFILE   PATH     SHUTDOWN  HIGH    LOW     HIGH    LOW     THRESH  THRESH  RATE   BUDGET  
05 = {str} '---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
06 = {str} '203  GP1100X   -            -        -        -    BBEFF2   255896      -                                         -     true     CXNK    none    -        -        -         disable  false     -7      -30     -7      -30     -16     10      5      0       
07 = {str} '215  GP1100X   -            -        -        -    BBEFBD   285359      -         GRIBBLE CHRISTIE                -     true     CXNK    none    -        -        -         disable  false     -7      -30     -7      -30     -16     10      5      0       
08 = {str} '223  GP4200XH  -            -        -        -    FCF5A1   307764      -         CRAWFORD PATRICK                -     true     CXNK    none    -        -        -         disable  false     -7      -30     -7      -30     -16     10      5      0       
09 = {str} '224  GP4200XH  -            -        -        -    FCF5A9   307775      -         TRIEBERT MICHAEL                -     true     CXNK    none    -        -        -         disable  false     -7      -30     -7      -30     -16     10      5      0       
10 = {str} '225  GP1100X   -            -        -        -    BBEFF0   265897      -         KNUTZEN PETER                   -     true     CXNK    none    -        -        -         disable  false     -7      -30     -7      -30     -16     10      5      0       
11 = {str} '226  GP4200XH  -            -        -        -    FCF4E9   307777      -         CARTWRIGHT JOHN E               -     true     CXNK    none    -        -        -         disable  false     -7      -30     -7      -30     -16     10      5      0       
12 = {str} '227  GP4200XH  -            -        -        -    FCF5A7   307776      -         PICA-WOOLEVER ADRIANNE          -     true     CXNK    none    -        -        -         disable  false     -7      -30     -7      -30     -16     10      5      0       
13 = {str} '228  GP4200XH  -            -        -        -    FCF4DE   307773      -         MIRACLE STUART DOUGLAS          -     true     CXNK    none    -        -        -         disable  false     -7      -30     -7      -30     -16     10      5      0       
14 = {str} '229  GP4200XH  -            -        -        -    FCF587   307771      -         HUFF JOSEPH A                   -     true     CXNK    none    -        -        -         disable  false     -7      -30     -7      -30     -16     10      5      0       

What I am wanting is the profile ID only which would be different values like
GP1100X, GP4200XH, etc…
My command that I usually run would be this
output = net_connect.send_command(“show running-config ont | tab”).split(‘\n’)
I would pick the str number. Can not do it in this scenario because the string keeps going

the code below is what I am running. The int(ouput) is just place holder until I figure out how to parse the data to get what I want

#!/usr/bin/python3
import netmiko.exceptions
from netmiko import ConnectHandler
from colorama import Fore, Back, Style
olts = {
    # 'Blue_Ridge-co': '192.168.240.55',
    'Blue_Ridge-HE': '192.168.240.52',
    'Briar_Patch': '192.168.240.50',
    'Bushy_Head': '192.168.240.48',
    'Hill_City': '192.168.240.47',
    'Holcomb': '192.168.240.51',
    'Jasper-CO': '192.168.240.46',
    'Juno': '192.168.240.49',
    'Mark_Miller': '192.168.240.54',
    'Talking_Rock': '192.168.240.45'

 }
for name, ip in olts.items():
    olt = {
        'device_type': 'cisco_ios',
        'ip': ip,
        'username': 'xxxxxx',
        'password': 'xxxxxx',

}
        #This is a loop for all onts
   # for devices in onts:
    net_connect = ConnectHandler(**olt)
    output = net_connect.send_command("show running-config ont | tab").split()
         int(output{})
    print(output)


 # This disconnects Script
net_connect.disconnect()

\
!
ont 403
profile-id GP1100X
serial-number 111C0CC
subscriber-id 307656
description “PERINE ANDREW”
!
ont 404
profile-id GP1100X
serial-number 111C0B0
subscriber-id 307657
description “PERINE ANDREW”
!
ont 413
profile-id GP1100X
serial-number 111BF33
subscriber-id 307806
description “GIARDINA DERRICK”
!

I got it figured out

\
ont_models = {}
for name, ip in olts.items():
olt = {
‘device_type’: ‘cisco_ios’,
‘ip’: ip,
‘username’: ‘sysadmin’,
‘password’: ‘sysadmin’,

}

print(f'Connecting to {name} at {ip}')
net_connect = ConnectHandler(**olt)
output = net_connect.send_command("show running-config ont").split('!\n')
for value in output[:-1]:
    model_details = value.split('\n')[1]
    model = (model_details.split()[1])
    if model in ont_models:
        ont_models[model] = ont_models[model] + 1
    else:
        ont_models[model] = 1

# This disconnects Script
net_connect.disconnect()

print(ont_models)

\
output
Connecting to Blue_Ridge-co at 192.168.240.55
Connecting to Blue_Ridge-HE at 192.168.240.52
Connecting to Briar_Patch at 192.168.240.50
Connecting to Bushy_Head at 192.168.240.48
Connecting to Hill_City at 192.168.240.47
Connecting to Holcomb at 192.168.240.51
Connecting to Jasper-CO at 192.168.240.46
Connecting to Juno at 192.168.240.49
Connecting to Mark_Miller at 192.168.240.54
Connecting to Talking_Rock at 192.168.240.45
{‘GP1100X’: 150, ‘GP4200XH’: 17, ‘GP1101X’: 1, ‘725GEa’: 52, ‘803G’: 22}

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.