Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > how to find a pattern in a file and get output in another file indifferent format

Reply
Thread Tools

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

 
 
vinitbhu
Guest
Posts: n/a
 
      03-17-2008
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.
 
Reply With Quote
 
 
 
 
GArlington
Guest
Posts: n/a
 
      03-17-2008
On Mar 17, 10:55 am, vinitbhu <vinitbh...@gmail.com> wrote:
> 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.
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      03-17-2008
On Mon, 17 Mar 2008 03:55:15 -0700 (PDT), vinitbhu
<> 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
--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
 
Reply With Quote
 
Lord Zoltar
Guest
Posts: n/a
 
      03-17-2008
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.
 
Reply With Quote
 
Mark Space
Guest
Posts: n/a
 
      03-17-2008
Roedy Green wrote:
> On Mon, 17 Mar 2008 03:55:15 -0700 (PDT), vinitbhu
> <> 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


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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
find a matching pattern in file and find it in another file too nani Perl Misc 2 03-14-2008 05:20 AM
Oracle JDeveloper: Good, bad or indifferent JT Java 3 06-30-2007 11:50 PM
Generics - good, bad or indifferent? TechBookReport Java 35 11-01-2005 10:36 AM
Why being an indifferent typist may be harmful Steven T. Hatton C++ 9 10-20-2004 02:39 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57