Converting Text file into excel sheet

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • argbsk
    New Member
    • Oct 2012
    • 2

    Converting Text file into excel sheet

    Following is the text file i have


    Test logname : DISK$REGRES:[VERIFICATION.AC C]ACC_diff.log
    FACILITY : ACC
    FAILED LOGINACCOUNTING TST
    Total : 42
    Passed : 41
    Failed : 1
    Not Run : 0

    Test logname : DISK$REGRES:[VERIFICATION.BA CKUP]BACKUP_diff.log
    FACILITY : BACKUP
    FAILED BACKUP_BEFORE
    FAILED BACKUP_INTERCHA NGE
    Total : 34
    Passed : 32
    Failed : 2
    Not Run : 0


    I want to covert it into proper excel sheet (I attached the excel sheet)
    Attached Files
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Have you attempted anything? I won't do your work for you. I will suggest the following steps:
    Read the file.
    Parse the data.
    Initialize a dictionary to store the data in an organized fashion.
    Iterate on the data.
    If the line of data has a colon (:), split the data and add to dictionary as in:
    Code:
    >>> line = "FACILITY : BACKUP"
    >>> dd = {}
    >>> line_list = [item.strip() for item in line.split(":")]
    >>> line_list
    ['FACILITY', 'BACKUP']
    >>> dd.setdefault(line_list[0], []).append(line_list[1])
    >>> dd
    {'FACILITY': ['BACKUP']}
    >>>
    If the line of code contains "FAILED":
    Code:
    >>> line = "FAILED LOGINACCOUNTINGTST"
    >>> if "FAILED" in line:
    ... 	dd.setdefault("FAILED", 0)
    ... 	dd["FAILED"] += 1
    ... 	
    0
    >>> dd
    {'FAILED': 1, 'FACILITY': ['BACKUP']}
    >>>
    After the data has been organized into a dictionary, create a CSV (comma separated value, the csv module is ideal for this) file for opening in Excel or write directly into Excel format with the xlwt module.

    Comment

    Working...