LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-04-2011, 03:14 AM   #1
joveniel
LQ Newbie
 
Registered: Feb 2011
Posts: 3

Rep: Reputation: 0
how display part of an output stream


Hello Guys.

I am a newbee in linux. Though I have little experience in the past, i just can't get to work what i have in mind.

i want to display part of an output stream.

cat sample.xml
<packet or="recv" ljid="d.sample@test.local/" ts="20110204T15:02:55"><message from='j.sample2@test.local/' to='d.sample@test.local' type='chat' xml:lang='en' id='sd61'><body>testing string</body><html><body style='font-style: normal; font-family: arial; color: #004200; font-size: 9pt; font-weight: normal'>testing string</body></html></message></packet>

i want to display only the following
to='d.sample@test.local'
from='j.sample2@test.local'
body=testing string

thanks,
jojo
 
Old 02-04-2011, 04:06 AM   #2
KamasCZ
LQ Newbie
 
Registered: Jan 2011
Location: Czech Republic, Tyniste n. O.
Distribution: Slackware
Posts: 22

Rep: Reputation: 1
Hi,
try this:
Code:
cat aaa.txt | sed -e 's/.*from/from/g' | sed -e 's/type.*<body>/body=/g' | sed -e 's/<\/body>.*//g'
it's ment to parse file with multiple lines of same type.
 
1 members found this post helpful.
Old 02-04-2011, 04:55 AM   #3
joveniel
LQ Newbie
 
Registered: Feb 2011
Posts: 3

Original Poster
Rep: Reputation: 0
Hi KamasCZ.

Thanks for your reply. Thaw was amazing.

It actually did the job. Though it was "from" and "body" attributes only, i just modified a little bit for my desired output.

But I have another problem. This file I am viewing is a log file. So when i try to use tail -f command instead of cat, it doesn't work.

Best regads,
jojo
 
Old 02-04-2011, 05:49 AM   #4
KamasCZ
LQ Newbie
 
Registered: Jan 2011
Location: Czech Republic, Tyniste n. O.
Distribution: Slackware
Posts: 22

Rep: Reputation: 1
Hi,
You must add -u flag (unbuffered) to each sed and it should work.
 
Old 02-10-2011, 02:03 AM   #5
joveniel
LQ Newbie
 
Registered: Feb 2011
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks for your reply.
I was able to get it already.
It was just --line-buffered for grep and -l for sed


tail -f log.xml | grep --line-buffered "body" | grep --line-buffered "recv" | sed -l 's/.*from=/from:/g' | sed -l 's/to=/to: /g' | sed -l 's/type.*<body>/body: /g' | sed 's/<\/body>.*//g'
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
File output redirection - possible to redirect stream to multiple files? EnderX Linux - Newbie 5 12-07-2010 11:39 PM
[SOLVED] OutPut IP into aFile - Part II NetRock Programming 2 05-13-2010 02:39 PM
ffmpeg - Unsupported codec for output stream #0.0 yitzle Linux - Software 4 01-30-2008 05:37 AM
How to output a C stream into a binary file readable via Fortran I/O? zero79 Programming 8 02-07-2005 09:51 PM
mplayer to output stream eantoranz Linux - Software 0 05-17-2004 03:47 PM


All times are GMT -5. The time now is 02:32 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration