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?
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?
sed:
sed '/^<JOB/,/^\/JOB/!d; /^<\/*JOB/d' infile
awk:
awk '/^<JOB/,/^\/JOB/ {if ( $0 ~ /^<\/*JOB/ ) {next} else {print}}' infile
if you have Python
#!/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
# ./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.