LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-03-2014, 02:32 AM   #1
ANU
Member
 
Registered: Aug 2003
Location: Romania
Distribution: Solaris 10
Posts: 78

Rep: Reputation: 15
Question python using splitlines or split?


Hi all

i have a script from which i get the output (i also save this output to a file in f1 = 20141202.194812_carStatus/):

Code:
---------------------------------------------
TM 05120970.01: Processing...
TM 05120970: Processing...
TM 05120970: current status Paid
TM 05120970: Owner_Info.User_ref = crossi14
TM 05120970: Owner_Info.Email = Criss.Rossi@gmail.com
TM 05120970: CarModel = Nissan Micra
----------------------------------------------
TM 05157414.06: Processing...
TM 05157414: Processing...
TM 05157414: current status Open
TM 05157414: Owner_Info.User_ref = yumiao12
TM 05157414: Owner_Info.Email = Yu.Miao@gmail.com
TM 05157414: CarModel = Toyota Avensis
----------------------------------------------
i used: exec_cmd('cat ' + f1 + '| grep -e "CarModel = " -e "Owner_Info.User_ref = "')
but i also need the first line (actually the second) of the block
TM 05157414.06: Processing...

what i try/need to do is, parse and and get the values in a variable for each of this blocks:

TM 05120970.v1 -> car_number = 05120970.01
Owner_Info.User_ref = crossi14 -> owner_user = crossi14
CarModel = Nissan Micra -> car_model = Nissan Micra

with this information i will added some default things like:
priority = Unknown

and i will need to have this variables as input for another script called insert_owner_car.pl:

Code:
insert_owner_car.pl -id 05120970.v1 -o owner_user="crossi14",car_model="Nissan Micra",priority="Unknown"
i tried using splitlines and then split after " = ", but somehow i dont get what i want, is there some other way to do this?
i really need help!
thank you

PS: i only have python 2.5.1

Last edited by ANU; 12-03-2014 at 02:36 AM.
 
Old 12-03-2014, 02:50 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,830

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
I'm really sorry, but what do you expect now? The only thing I can say: yes, probably there is some other way to do that.
How did you try and what, what was the result, what did you expect and what did you get?....
 
Old 12-03-2014, 04:13 AM   #3
ANU
Member
 
Registered: Aug 2003
Location: Romania
Distribution: Solaris 10
Posts: 78

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by pan64 View Post
I'm really sorry, but what do you expect now? The only thing I can say: yes, probably there is some other way to do that.
How did you try and what, what was the result, what did you expect and what did you get?....
well i mentioned that i used the splitlines and split after the "=" sign, but it didnt work properly
i put them in a for loop, and i got all confused
so im actually looking for someone that can help me out, one way or the other

[code]
for line in f:
line = line.strip()
columns = line.split(" = ", 1)
name = columns[-1]
if name.find('status') == -1:
if name.find('-----------') == -1:
if name.find('@gmail') == -1:
print name
[code]

i need to read a block of text between two identical strings ("-----------")
and then split(" = ")
but i still cant figure out how i can get that car number thingy: 05120970.01
put everything in a loop, and repeat for each block of text

Last edited by ANU; 12-03-2014 at 09:29 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Strange return from python split() function sharky Programming 3 06-26-2014 04:15 PM
[SOLVED] [PYTHON] Split a string by every nth characters recuse44 Programming 4 01-20-2011 03:34 AM
package management (to split or not to split packages) frischi Linux - Desktop 2 05-06-2010 03:15 PM
Split header from data in file using python pwc101 Programming 13 06-16-2009 07:27 PM
How to split file , .. awk or split ERBRMN Linux - General 9 08-15-2006 12:02 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration