Parsing data in a file containing systeminfo information

Asked

Viewed 39 times

0

A "txt" file containing command return information was generated systeminfo, and I need to be able to copy some of the lines of the file, in this case, the ones that contain information about: total physical memory, available physical memory, virtual memory, maximum size, available and in use:

Total Physical Memory: 16.282 MB
Available Physical Memory: 10.111 MB
Virtual Memory: Max Size: 18.714 MB
Virtual Memory: Available: 10.798 MB
Virtual Memory: In Use: 7.916 MB

To get the executed file at the prompt: systeminfo > saida_systeminfo.txt

Follow code under development:

archive_sysinfo = open('saida_systeminfo.txt', 'r')
text_sysinfo = archive_sysinfo.readlines()
lista_linhas2 = []
lista_info = []

for linha2 in text_sysinfo:
    lista_linhas2.append(linha2.split())
    print(linha2.split())

for linha2 in lista_linhas2:
    if "Mem¢ria" in linha2:
    lista_info.append(linha2[0:5])

lista_info = open("resultado_info.txt","w")
lista_info.write("Coletando dados de memoria")

string_info = ""
for j in range(0,7,1):
    string_info = lista_info[j][0] + " " + lista_info[j][1] + " " + 
lista_info[j][2] + " " + lista_info[j][3] + " " + lista_info[j][4] + "\n"
    print(string_info)
    lista_info.write(string_info)
  • It would be interesting to edit the answer and add an example of the file structure you are reading, otherwise there is no way to know where the information is or how it is stored. It would also be productive to explain what the expected outcome would be and what is not working. Specify a little more what "I couldn’t finish the program" means so that other people have more information to help you.

  • is done, see if it gets clearer

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.