LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 07-17-2009, 11:26 PM   #1
AutoC
Member
 
Registered: Jan 2008
Posts: 30

Rep: Reputation: 15
SED multiline pattern matching


Hi,
I have an xml file that has multiple entries like..

Quote:
<recording audio="011/011o031e.sph" name="1e">
<segment lang="en_US">
<orth>
Midlantic ,comma a New Jersey bank stock ,comma was up three
quarters to forty seven and three eighths .period
</orth>
</segment>
</recording>
I need to parse each entry, create a file based on audio="",for eg. I need to create 011/011o031e.t and write the stuff between <orth> and </orth> in the file.
any help?
 
Old 07-18-2009, 12:04 AM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
awk
Code:
awk '/audio/{
 for(i=i;i<=NF;i++){
    if($i ~ /audio/){
        gsub(/.*audio=\"|\//,"",$i)
        gsub(/\..*\".*/,"",$i)
        filename = $i".t"
    }   
 }
}
/<\/orth>/{f=0;}
/<orth>/{f=1;next}
f {   print $0 > filename }' file
 
  


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
sed: pattern matching with newlines anjanesh Linux - General 2 02-20-2009 06:36 AM
complicated pattern matching with awk or sed... alirezan1 Linux - Newbie 1 10-10-2008 06:45 PM
vim or sed multiline regexp matching eentonig Programming 1 09-08-2008 09:06 AM
Sed pattern matching digitalbrutus Programming 1 08-20-2006 01:37 PM
pattern matching problem in sed digitalbrutus Programming 4 08-20-2006 04:40 AM

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

All times are GMT -5. The time now is 03:46 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
Open Source Consulting | Domain Registration