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

V

vinitbhu

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.
 
G

GArlington

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

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

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.

And then you can choose any XML processor/parser to do that.
 
L

Lord Zoltar

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.
 
M

Mark Space

Roedy said:
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

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top