Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Parsing a delimited text file

 
Kamal Ahmed
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • 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.
 
Svend Rost
Ranch Hand
Posts: 904
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • 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
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • 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.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic