![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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> ================== |
|
||||
|
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()
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"/> |
|
||||
|
Thanks guys.
|
| Sponsored Links | ||
|
|