|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Jan 2002
Messaggi: 997
|
Da file di testo a xls
Hola. Ho un file di testo così composto:
Codice:
IAD: 1 IP: 101.84.187.66 FIRMWARE: 4.0.16 MODELLO: SV1242 IAD: 2 IP: 101.58.8.83 FIRMWARE: 4.0.18 MODELLO: SV1242 IAD: 3 IP: 101.84.186.83 IAD: 4 IP: 101.78.208.2 IAD: 5 IP: 101.84.43.139 MODELLO: ViNE2100 FIRMWARE: 3.2.1g IAD: 6 IP: 101.84.20.13 FIRMWARE: 4.0.16 MODELLO: SV1242 IAD: 7 IP: 101.78.24.228 IAD: 8 IP: 101.69.169.235 MODELLO: ViNE1000 FIRMWARE: 2.3.4b IAD: 9 IP: 101.58.8.194 FIRMWARE: 4.0.18 MODELLO: SV1242 Codice:
IAD IP MODELLO FIRMWARE 1 101.84.187.66 SV1242 4.0.16 2 101.58.8.83 SV1242 4.0.18 3 101.84.186.83 DOWN DOWN 4 101.78.208.2 DOWN DOWN 5 101.84.43.139 ViNE2100 3.2.1g 6 101.84.20.13 SV1242 4.0.16 7 101.78.24.228 DOWN DOWN 8 101.69.169.235 ViNE1000 2.3.4b 9 101.58.8.194 SV1242 4.0.18 Contate che, importazione in excel a parte, devo poter fare tutto da shell. Idee? Ultima modifica di dAbOTZ : 07-08-2011 alle 15:36. |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Apr 2006
Messaggi: 22462
|
è strettamente necessario che tu esporti in formato xls o ti puoi accontentare di un più semplice csv?
Oltre alla shell (bash immagino), cos'altro hai a disposizione? che ne so, un interprete python?
__________________
amd a64x2 4400+ sk939;asus a8n-sli; 2x1gb ddr400; x850 crossfire; 2 x western digital abys 320gb|| asus g1
Se striscia fulmina, se svolazza l'ammazza |
|
|
|
|
|
#3 |
|
Senior Member
Iscritto dal: Jan 2002
Messaggi: 997
|
L'xls verrà poi, csv andrebbe benone. Python all'occorrenza posso installarlo, come più o meno qualunque altro strumento utilizzabile via shell.
|
|
|
|
|
|
#4 |
|
Senior Member
Iscritto dal: Apr 2006
Messaggi: 22462
|
se puoi usare python, ho improvvisato uno scriptino che dovrebbe fare al caso tuo.
la qualità è bassa (è il primo script in python che faccio) e anche contando l'ora... Comunque ecco a te Codice:
import sys
class router:
attributi={"IAD":""}
print "log parser"
if(len(sys.argv)<2):
print "missing input file"
exit()
else:
print len(sys.argv)
fInput=open(sys.argv[1],"r")
if(len(sys.argv)==2):
fOutput=sys.stdout
else:
fOutput=open(sys.argv[2],"w")
routers =[]
def printToFile(r):
if r.attributi["IAD"]=="":
return
str=r.attributi["IAD"]+"\t"+r.attributi["IP"]+"\t";
if r.attributi.has_key("MODELLO"):
str+= r.attributi["MODELLO"]
else:
str+= "DOWN"
str+="\t"
if r.attributi.has_key("FIRMWARE"):
str+= r.attributi["FIRMWARE"]
else:
str+= "DOWN"
str+="\t"
fOutput.write(str+"\n")
def load():
r= router()
while True:
testo=fInput.readline()
if testo =="":
printToFile(r)
break
index=testo.find(":");
intestazione=testo[:index]
dato=testo[index+1:len(testo)-1]
#print intestazione,"-->",dato
if intestazione=="IAD":
printToFile(r);
r=router()
r.attributi={}
#print "\n---\n"
r.attributi[intestazione]=dato
load()
Ho usato come file di esempio quello da te postato e funziona
__________________
amd a64x2 4400+ sk939;asus a8n-sli; 2x1gb ddr400; x850 crossfire; 2 x western digital abys 320gb|| asus g1
Se striscia fulmina, se svolazza l'ammazza Ultima modifica di wizard1993 : 19-12-2010 alle 00:24. |
|
|
|
|
|
#5 |
|
Senior Member
Iscritto dal: Jan 2002
Messaggi: 997
|
Funziona egregiamente, proprio quel che mi serviva. Grande, ti devo una birra.
|
|
|
|
|
|
#6 |
|
Senior Member
Iscritto dal: Apr 2006
Messaggi: 22462
|
di nulla, se ti serve altro non hai che da chiedere
__________________
amd a64x2 4400+ sk939;asus a8n-sli; 2x1gb ddr400; x850 crossfire; 2 x western digital abys 320gb|| asus g1
Se striscia fulmina, se svolazza l'ammazza |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 23:27.



















