• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 224
  • Last Modified:

pattern matching


Hi
Below is text file...
Please help me grepping out the text between the tags <LOC> and </LOC>.

<LINE><ADM>DOLNOSLASKIE</ADM><LOC>BARDO</LOC><LOC1>OPOLNICA</LOC1><POCO>57-256</POCO><TYPE>Old
Name</TYPE><ADMSYN>WALBRZYSKIE<TYPE>OldName</TYPE></ADMSYN></LINE>
<LINE><ADM>DOLNOSLASKIE</ADM><LOC>BARKOWO K. MILICZA</LOC><LOC1>BARKOWO</LOC1><POCO>55-143</PO
CO></LINE>
<LINE><ADM>DOLNOSLASKIE</ADM><LOC>BARKOWO K. MILICZA</LOC><LOC1>BARKóWKO</LOC1><POCO>55-143</P
OCO></LINE>
<LINE><ADM>DOLNOSLASKIE</ADM><LOC>BARKOWO K. MILICZA</LOC><LOC1>KêDZIE</LOC1><POCO>55-143</POC
O></LINE>


waiting for a favourable reply

Regards
Biju Pillai
0
pillaib
Asked:
pillaib
1 Solution
 
prady_21Commented:

This should work

if ( /<LOC>(.*)<\/LOC>/ ) {
      print "$1\n";
}

0
 
ozoCommented:
while( /<LOC>(.*?)<\/LOC>/g ){
     print "$1\n";
}
0
 
TintinCommented:
or as a single line

print "$1\n" while (/<LOC>(.*?)<VLOC>/);
0
 
hemaraj123Commented:
I will agree with all the above three, but whenever you have an enter mark in between <LOC> and </LOC>, then all the above three will fail, for that below code will work for all.

while (/<LOC>(.*?)<\/LOC>/s) {
  print $1."\n";
}
0
 
jmcgOwnerCommented:
Nothing has happened on this question in over 7 months. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to
accept answer by hemaraj123.

Please post any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now