help with grabbing data out of file

Associate
Joined
8 Mar 2007
Posts
2,176
Location
between here and there
hey guys,

I have a xml file which has loads of data in it. I need to read though the file and grab all the strings that fall between two known nodes.

example structer;

Code:
<Message Date="22/02/2011" Time="14:31:15" DateTime="2011-02-22T14:31:15.817Z" SessionID="1">
	<From>
		<User FriendlyName="[email protected]"/>
	</From>
	<To>
		<User FriendlyName="[email protected] (E-mail Address Not Verified)"/>
	</To>
	<Text Style="font-family:Segoe UI; color:#000000; ">
		message text
	</Text>
</Message>

<Message Date="22/02/2011" Time="14:47:02" DateTime="2011-02-22T14:47:02.019Z" SessionID="2">
	<From>
		<User FriendlyName="[email protected]"/>
	</From>
	<To>
		<User FriendlyName="[email protected] (E-mail Address Not Verified)"/>
	</To>
	<Text Style="font-family:Segoe UI; color:#000000; ">
		message text.....
	</Text>
</Message>

if i can get everything between '<Message Date' and '</Message>' into a variable so i end up with a load of variables, I'd be really happy :)

any ideas?

I have a feeling awk is what i need to use but i have no idea how!

thanks
 
i saw that but i have NO perl experience, so was unable to get any of those solutions to work. mainly because i don't know how to use the suggested code on the back of standard in on my file.

any other suggestions?
 
WOW, what a response!

I should have explained a little better, so let me try again...

We (at work) are thinking of getting into bed with a new lync server. However untill we weigh up all the options and decide if it's worth the cost, I've been asked to try and keep tabs on msn conversions in the office as all staff use msn to talk to each other and customers.

Since the newer version of msn, I'm unable to sniff the non-standard port that msn uses and grab the data that way. (New versions uses port 80 so thats not going to work)

I've written a logon script that copies the users xml history data to dumps it on a ftp server. I've then got a linux webserver that picks this data up via a cron job, now I want to go through each xml file for each user and get the data out of ever node in the xml, then import that data into mysql.

I'll have a bash with the awk code you've supplied, but in the mean time, if you can think of a better solution, I'd be very grateful.

Thanks again, and I'll update once I'v had a chance to try and implement your suggestions.

Blastman
 
Back
Top Bottom