Click here to Skip to main content
15,890,186 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
data = '''
eth 0, address 001, type ethernet
device native, cast established.
em 1, address 002, type ethernet
device native, cast exit
eth 2, address 003, type ethernet
device native, cast rescue0b0
loopback 3, address 003, type ethernet
device native
'''

1st : I need to split the data like:

split0:
eth 0, address 001, type ethernet
device native, cast established.
split1:
em 1, address 002, type ethernet
device native, cast exit
split2:
eth 2, address 003, type ethernet
device native, cast rescue0b0

and so on...

2nd I need to split the data per line so that I can fetch the below details.

split0:1 eth 0,
split0:2 address 001
split0:3 type ethernet
split0:4 device native << new line here...
and continue for all other primary splits as well.
split2: and 3


its not mandatory to have fixed value at the end of each paragraph. The logic here is new interface paragraph always start without a space. I need that logic.

What I have tried:

i have tried multiple things but not getting any repose from python split.
Posted
Comments
Richard MacCutchan 10-Nov-17 10:51am    
Your problem seems to be that there is no distinct character or character sequence that can be used to separate the text at the places you want. You will need to read each line and then combine the parts that should go together by checking for keywords in each line.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900