how to parse a particular output like in rows as the output comes in a clubbed way in python?
Question: When I run the code below, the output comes as such. I need the output to show
in rows **and** only the values under the caption.

Desired output:

    
    
    caption : 3PAR
              3PAR
    

Actual output:

    
    
    ('Caption                          DeviceID             Model                            Partitions  Size         \r\r\n3PARdata VV SCSI Disk Device     \\\\.\\PHYSICALDRIVE19  3PARdata VV SCSI Disk Device     0           1069286400   \r\r\nHP P2000 G3 FC SCSI Disk Device  \\\\.\\PHYSICALDRIVE1   HP P2000 G3 FC SCSI Disk Device  1           49993251840  \r\r\nHP HSV360 SCSI Disk Device       \\\\.\\PHYSICALDRIVE7   HP HSV360 SCSI Disk Device       4           1069286400   \r\r\nHP HSV360 SCSI Disk Device       \\\\.\\PHYSICALDRIVE27  HP HSV360 SCSI Disk Device       0           1069286400   \r\r\nHP HSV360 SCSI Disk Device       \\\\.\\PHYSICALDRIVE5   HP HSV360 SCSI Disk Device       0           1069286400   \r\r\nHP P2000 G3 FC SCSI Disk Device  \\\\.\\PHYSICALDRIVE23  HP P2000 G3 FC SCSI Disk Device  1           49993251840  \r\r\n3PARdata VV SCSI Disk Device     \\\\.\\PHYSICALDRIVE13  3PARdata 
    

Code:

    
    
    p5=subprocess.Popen("rsh -l Administrator 10.10.11.37 \"wmic diskdrive list brief\"",stdout=subprocess.PIPE, shell=True)
    
    
    result = p5.communicate()
    status = p5.wait()
    print(result),
    


Answer: If you only want the values under `Caption` then use `re` to split on the
space after `Disk Device` which is common in all Caption rows:

    
    
    result = """Caption                          DeviceID             Model                            Partitions  Size         \r\r\n3PARdata VV SCSI Disk Device     \\\\.\\PHYSICALDRIVE19  3PARdata VV SCSI Disk Device     0           1069286400   \r\r\nHP P2000 G3 FC SCSI Disk Device  \\\\.\\PHYSICALDRIVE1   HP P2000 G3 FC SCSI Disk Device  1           49993251840  \r\r\nHP HSV360 SCSI Disk Device       \\\\.\\PHYSICALDRIVE7   HP HSV360 SCSI Disk Device       4           1069286400   \r\r\nHP HSV360 SCSI Disk Device       \\\\.\\PHYSICALDRIVE27  HP HSV360 SCSI Disk Device       0           1069286400   \r\r\nHP HSV360 SCSI Disk Device       \\\\.\\PHYSICALDRIVE5   HP HSV360 SCSI Disk Device       0           1069286400   \r\r\nHP P2000 G3 FC SCSI Disk Device  \\\\.\\PHYSICALDRIVE23  HP P2000 G3 FC SCSI Disk Device  1           49993251840  \r\r\n3PARdata VV SCSI Disk Device     \\\\.\\PHYSICALDRIVE13  3PARdata"""
    import re
    spl = result.splitlines()
    print(spl[0].split()[0].rstrip())
    for line in spl[1:]:
        if line:
            print(re.split("(?<=Disk Device)\s+",line,1)[0])
    
    Caption
    3PARdata VV SCSI Disk Device
    HP P2000 G3 FC SCSI Disk Device
    HP HSV360 SCSI Disk Device
    HP HSV360 SCSI Disk Device
    HP HSV360 SCSI Disk Device
    HP P2000 G3 FC SCSI Disk Device
    3PARdata VV SCSI Disk Device
    

