Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2008

Tip: Looking for answers? Try searching our database.

how to find a pattern in a file and get output in another file in     different format

Thread view: 
vinitbhu - 17 Mar 2008 11:55 GMT
Hello members,

I am very new in Java programming, I want some help from you.
Actually  I have one file named as "list01.txt" in which the content
is in following format

Record # 1
Au: Kuzur, A  D
Au: Dito, Bolte
Ti: Elements of semantic web.
Pu: Nasadac
Pl: New Delhi

Record # 2
Au: Kumar, Vinit
Ti: Learning how to learn.
Pu: Pooja
Pl: Bangalore

Record # 3
Au: Pandey, Anand K
Ti: Emerging minds.
Pu: Lakhotia
Pl: Varanasi

what I am trying to do is to get output in some new files in following
format

In file record1.txt
<author> Kuzur, A  D</author>
<author>Dito, Bolte </author>
<title> Elements of semantic web.</title>
<publisher> Nasadac</publisher>
<place>New Delhi</place>

In file "record2.txt"
<author> Kumar, Vinit</author>
<title> Learning how to learn.</title>
<publisher> Pooja</publisher>
<place>Bangalore</place>

In file "record3.txt"
<author> Pandey, Anand K</author>
<title> Emerging minds.</title>
<publisher> Lakhotia</publisher>
<place> Varanasi</place>

can anybody help me I am new to Java.
thanks.
GArlington - 17 Mar 2008 12:16 GMT
> Hello members,
>
[quoted text clipped - 20 lines]
> Pu: Lakhotia
> Pl: Varanasi

You will need (custom) file reader to get this file format into XML-
like document.

> what I am trying to do is to get output in some new files in following
> format
[quoted text clipped - 20 lines]
> can anybody help me I am new to Java.
> thanks.

And then you can choose any XML processor/parser to do that.
Roedy Green - 17 Mar 2008 13:07 GMT
On Mon, 17 Mar 2008 03:55:15 -0700 (PDT), vinitbhu
<vinitbhu06@gmail.com> wrote, quoted or indirectly quoted someone who
said :

>Au: Pandey, Anand K

you can read the file with CSVReader. Just tell is your field
separator is a ':' insteao of the usual ','.

See http://mindprod.com/jgloss/csv.html
Signature


Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Mark Space - 17 Mar 2008 16:43 GMT
> On Mon, 17 Mar 2008 03:55:15 -0700 (PDT), vinitbhu
> <vinitbhu06@gmail.com> wrote, quoted or indirectly quoted someone who
[quoted text clipped - 6 lines]
>
> See http://mindprod.com/jgloss/csv.html

I would not do this, just because it would be easy for a book title to
have ":" in it.

I'd have to see the actual file format spec, but it looks like the
identifier for the record type is always two letters at the beginning of
the line.  I'd key off that.  Just use readLine(), and check char(0) and
char(1).  Dead simple, and bomb proof.  Most likely faster too.
Lord Zoltar - 17 Mar 2008 16:25 GMT
You can get the data from the file with regular expressions and
groupings. I haven't tried it, but this expression:
Record\ \#\ ([0-9])\ \n(Au: .+\n){1,}(Ti: .+\n)(Pu: .+\n)(Pl: .+)
would probably match well with what you want.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.