• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Parsing a delimited text file

 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Are there any good resources on the web where i can learn how to parse a delimited text file, and save the data in a map data structure.

Thanks,

I would appreciate any help,

-Kamal.
 
Ranch Hand
Posts: 904
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your question isn't very specific.. which makes it abit harder to help you.

Parsing:
Try Google

Map datastructure:
java.util.Map

/Svend Rost
 
Kamal Ahmed
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry about that.

I have a text file:
sev=5|evt="DNS"|sip=111.222.111.222|dip=101.101.101.101|rv47="Vulnerable"|rv44="Unix"|st=N
sev=2|evt="DNS"|sip=111.222.111.222|dip=101.101.101.101|rv47="Vulnerable"|rv44="Unix"|st=N
sev=4|evt="DNS"|sip=111.222.111.222|dip=101.101.101.101|rv47="Vulnerable"|rv44="Unix"|st=N
sev=3|evt="DNS"|sip=111.222.111.222|dip=101.101.101.101|rv47="Vulnerable"|rv44="Unix"|st=N
sev=5|evt="DNS"|sip=111.222.111.222|dip=101.101.101.101|rv47="Vulnerable"|rv44="Unix"|st=N
sev=5|evt="DNS"|sip=111.222.111.222|dip=101.101.101.101|rv47="Vulnerable"|rv44="Unix"|st=N|sleep=60
sev=5|evt="DNS"|sip=111.222.111.222|dip=101.101.101.101|rv47="Vulnerable"|rv44="Unix"|st=N
sev=5|evt="DNS"|sip=111.222.111.222|dip=101.101.101.101|rv47="Vulnerable"|rv44="Unix"|st=N

Now i need to write a parser which will parse these name / value pairs, and populate a Map.

I appreciate your help.
Thanks,

-Kamal.
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For the parsing, use String.split() if you are developing with Java 1.4 or above. Otherwise, look at StringTokenizer.

Layne
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JDK 1.4 also offers regular expressions, and JDK 5 builds on regex with a nifty goodie called Scanner. So many choices! Layne's suggestions are the easiest by far, and a great place to start. Have fun, let us know what you wind up with.
 
So it takes a day for light to pass through this glass? So this was yesterday's tiny ad?
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic