The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Please help to write a executable script for extracting some parts of a file iammitra Shell Programming and Scripting 9 05-13-2009 10:34 AM
How to extract some parts of a file to create some outfile iammitra Shell Programming and Scripting 21 05-11-2009 11:06 AM
getting parts of a file bebop1111116 Shell Programming and Scripting 11 10-09-2006 10:19 AM
filter parts of a big file using awk or sed script apalex Shell Programming and Scripting 1 07-25-2005 04:45 PM
cksum parts of a file crazykelso UNIX for Dummies Questions & Answers 6 07-30-2002 11:38 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-27-2009
srivat79 srivat79 is offline
Registered User
  
 

Join Date: May 2009
Posts: 6
Extracting parts of a file.

Hello,

I have a XML file as below and i would like to extract all the lines between <JOB & </JOB> for every such occurance. The number of lines between them is not fixed.

Anyways to do this awk?

============
<JOB APR="1" AUG="1" DEC="1" FEB="1" JAN="1" JUL="1" JUN="1" MAR="1" MAY="1" NOV="1" OCT="1" SEP="1" >
<QUANTITATIVE NAME="B2_ADJ" QUANT="1"/>
<QUANTITATIVE NAME="B2_NR" QUANT="1"/>
</JOB>
<JOB APR="1" AUG="1" DEC="1" FEB="1" JAN="1" JUL="1" JUN="1" MAR="1" MAY="1" NOV="1" OCT="1" SEP="1" >
<QUANTITATIVE NAME="B2_ADJ" QUANT="1"/>
<QUANTITATIVE NAME="B2_NR" QUANT="1"/>
</JOB>

==================
  #2 (permalink)  
Old 05-27-2009
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,257
sed:
Code:
sed '/^<JOB/,/^\/JOB/!d; /^<\/*JOB/d' infile
awk:
Code:
awk '/^<JOB/,/^\/JOB/ {if ( $0 ~ /^<\/*JOB/ ) {next} else {print}}' infile
  #3 (permalink)  
Old 05-27-2009
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,422
if you have Python
Code:
#!/usr/bin/env python
f=0
for line in open("file"):
    if "</JOB" in line: f=0;continue
    if "<JOB" in line:
        f=1
        continue
    if f: print line.strip()
output
Code:
# ./test.py
<QUANTITATIVE NAME="B2_ADJ" QUANT="1"/>
<QUANTITATIVE NAME="B2_NR" QUANT="1"/>
<QUANTITATIVE NAME="B2_ADJ" QUANT="1"/>
<QUANTITATIVE NAME="B2_NR" QUANT="1"/>
  #4 (permalink)  
Old 05-27-2009
srivat79 srivat79 is offline
Registered User
  
 

Join Date: May 2009
Posts: 6
Thanks guys.
Sponsored Links
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 03:35 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0