Python - Manipular datos output

 
Vista:

Manipular datos output

Publicado por Edison (1 intervención) el 23/07/2019 03:41:16
Actualmente tengo un problema para manipular los datos de output para poderlos separar por comas y traer la informacion por lineas y no por palabras, que a su vez se guarda en un archivo csv. con la respectiva direcion Ip del dispositivo de red.

Codigo Utilizado

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#Connect to a device
net_connect = make_connection(ip, username, password)
#Run a command and set that to outputint1eeb
output = net_connect.send_command_expect('show run | i ssh')
#Using the split command to cut up the output based on a space
#for each_word in output.split(" "):
for each_word in output.split(" "):
    print (output)
    #Then find the part with .bin in it, which will be the IOS file name
    if "ssh"  in each_word:
    # #And tie that file name to a varable
        ver = each_word
    # 	print (ver)
#Next we'll set a varable to the IP and the IOS with a "," between them, perfect for CSVs.
results = ip + "," + ver
#Next we will append the output to the results file
to_doc_a(file_name, results)

Output

ip ssh time-out 60
ip ssh version 2
transport input ssh
transport input ssh
ip ssh time-out 60
ip ssh version 2
transport input ssh
transport input ssh
ip ssh time-out 60
ip ssh version 2
transport input ssh
transport input ssh
ip ssh time-out 60
ip ssh version 2
transport input ssh
transport input ssh

Adjunto archivo con el resultado donde solo me traer la palabra selecciona y no la linea completa.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder