Click here to Skip to main content
13,766,267 members
Rate this:
 
Please Sign up or sign in to vote.
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 10-Nov-17 5:21am
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web01-2016 | 2.8.181114.1 | Last Updated 10 Nov 2017
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100