aspose file tools*
The moose likes Beginning Java and the fly likes Parsing a delimited text file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Parsing a delimited text file" Watch "Parsing a delimited text file" New topic
Author

Parsing a delimited text file

Kamal Ahmed
Ranch Hand

Joined: Feb 15, 2005
Posts: 91
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

Joined: Oct 23, 2002
Posts: 904
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

Joined: Feb 15, 2005
Posts: 91
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

Joined: Dec 06, 2001
Posts: 3061
For the parsing, use String.split() if you are developing with Java 1.4 or above. Otherwise, look at StringTokenizer.

Layne


Java API Documentation
The Java Tutorial
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
jQuery in Action, 2nd edition
 
subject: Parsing a delimited text file
 
Similar Threads
Flat file to database?
Data Files , All members are invited to give their OPINIONS
Loading Data in Table
How to insert data from file excel into DB?
Complex text-file-to-text-file conversion