Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: HOW TO PARSE A TEXT FILE

  1. #1
    Junior Member
    Join Date
    May 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default HOW TO PARSE A TEXT FILE

    Hello,

    What you see below stars-line is the type of data i am working with.
    I have a lot of file like that. Initially, i don't know what the files look like.
    It is the user of the application that has to input the files.
    The user first gives example data to the system. ie. The user can give as example:
    Name: Jhon Smith
    Address: 36, abcd avenue, Paris

    My application has to know how to parse the file, so it puts the data in a database.
    As you can see, using simple delimitters (eg: space, comma,...) or regular expressions will not work.

    Does anyone has an idea how to appoaroch this problem?

    I am opened to any type of suggestion.

    Regards,

    Herve
    ********************************************
    name id beer_style first_brewed alcohol_content original_gravity final_gravity ibu_scale country brewery_brand color_srm from_region containers
    Bramling /m/0cttpqn 4.0 Buntingford Brewery
    Dark Star Hophead Extra /m/0dl8hjd 5.8 Dark Star
    Brewers Gold /m/0cttps0 Bitter 4.0 Crouch Vale Brewery
    Wem Brewing Company Cascade Bitter /m/0dlfhn2 Wem Brewing Company
    Friedrich Dull Krautheimer Urtyp Dunkel /m/04dqd7m 5.4 Friedrich Dull Germany /m/04dr2qr
    Nethergate Umbel Ale Coriander Beer /m/04dqf7b 3.8 Nethergate brewery United Kingdom /m/04dr00w
    Skinner's Cornish Gold /m/04dqmzy 5.1 Skinner's Brewery United Kingdom /m/04dr1kh
    Brouwerij Martens Damburger Export /m/04dqrz0 5.1 Brouwerij Martens Belgium /m/04dr6cb
    Concord Brewers Rapscallion Premier /m/04dqt4r 6.75 Concord Brewers United States of America /m/04dr2fm
    Federation High Level Strong Brown Ale /m/04dqhp1 4.5 Federation United Kingdom /m/04dr2n_
    Chiltern Brewery Glad Tidings Spiced Milk Stout /m/04dqv4g 4.6 Chiltern Brewery United Kingdom /m/04dr57q
    Huisbrouwerij Klein Duimpje Hillegoms Tarwe Bier /m/04dqhd9 5.0 Huisbrouwerij Klein Duimpje Netherlands /m/04dqztr
    Wickwar Infernal Brew /m/04dqfy6 4.8 Wickwar United Kingdom /m/04dq_9r
    Schöfferhofer Hefeweizen /m/04dqtxc 5.0 Schöfferhofer Germany /m/04dr0zh
    Woodforde's Nelson's Revenge /m/04dqqg3 4.5 Woodforde’s Brewery United Kingdom /m/04dr6c6
    Ridgeway Santa's Butt Winter Porter /m/04dqlpv 6.0 Ridgeway United Kingdom /m/04dqzdh
    De Proefbrouwerij Kapel van Viven blond /m/04dqjhh 6.8 De Proefbrouwerij Belgium /m/04dr28r
    Ventnor Wight Spirit /m/04dqkb9 5.0 Ventnor United Kingdom /m/04dr6h2
    Wye Valley Brewery O'er The Sticks /m/04dqkxg 4.5 Wye Valley Brewery United Kingdom /m/04dr6w2
    Cannery Blackberry Porter /m/04dqbfw 8.0 Cannery Canada /m/04dr4s5
    Maclay Thistle MacKinnon's Curse (Asda) /m/04dqfzr 4.1 Maclay Thistle United Kingdom /m/04dr58z
    Alcazar (Sherwood Forest Brewery Co) Maiden's Magic /m/04dq9h7 5.0 Alcazar (Sherwood Forest Brewing Co) United Kingdom /m/04dq_hm
    Molson Stock Ale /m/04dqqkm 5.0 Molson Canada
    Hirter Privat Pils /m/04dql0d 5.2 Hirter Austria /m/04dr2tr
    Lodzkie (subsidiary of Kaltenberg) Glob Premium /m/04dqd05 5.5 Lodzkie (subsidiary of Kaltenberg) Poland /m/04dqxcr
    Batemans Spring Breeze /m/04dqgsb 5.0 Batemans Brewery United Kingdom /m/04dr023
    Wylam Toon Ale Brunette /m/04dqf1f 4.8 Wylam Brewery United Kingdom /m/04dr0q7
    Brouwerij 't IJ Vlo /m/04dqvww 7.0 Brouwerij 't IJ Netherlands /m/04dqywr
    Roman Ename Tripel /m/04dqt36 9.0 Roman Belgium /m/04dr2xw
    De Leckere Tripel /m/04dqk96 8.0 De Leckere Netherlands /m/04dr6_6
    Haacht Charles Quint/Keizer Karel /m/04dqk4v 9.0 Haacht Belgium /m/04dq_tm
    Integrated Bottling Solutions Hazy Days /m/04dqj6k 3.9 Integrated Bottling Solutions United Kingdom /m/04dr0wc
    Usher's White Ale /m/04dqsbh 6.5 Usher's United Kingdom /m/04dr3l4
    Robinson's Top Tipple /m/04dqwpg 3.9 Robinson's Brewery United Kingdom /m/04dqxz3
    Broughton Ales Merlin's Ale /m/04dqd1q 4.2 Broughton Ales United Kingdom /m/04dq_37
    Copper Dragon Brewery Black Gold /m/0dl8hft Mild ale 3.7 Copper Dragon Brewery
    Dark Star Old ale /m/0dl8hk4 4.0 Dark Star
    Abbey Ales Bath Star /m/0djv0x0 Bitter Abbey Ales Brewery
    St. James Irish Red Ale /m/063wb2t Irish red ale Walnut Brewery
    Island Lager /m/05khjyc Lager 5.0 Granville Island Brewing
    Tooheys Old /m/07qzs6 1869 4.4 Tooheys Australia
    Creemore Springs /m/02mjg8 Lager,Pilsener,Bock 1987 Canada
    Ommegang Hennepin /m/02hv3dd Saison Brewery Ommegang
    James Squire Hop Thief /m/03m2n3j Australia
    Meyer E.S.B. /m/063hm84 Extra Special/Strong Bitter Thirsty Bear Brewing Company
    Otley CO2 /m/0djz9_0 Special/Best/Premium Bitter Otley Brewing Company Limited
    Otley O8 /m/0djz9zy Barley wine Otley Brewing Company Limited
    Saint Arnold Divine Reserve 10 /m/0ghtv0j English Barleywine 2010 11.0 1.101 1.018 Saint Arnold Brewing Company United States of America /m/0ghtv1y
    Otley Dark-O /m/0djz9_9 Mild ale Otley Brewing Company Limited
    First Lightning /m/0cttpnj 4.6 Atomic Brewery
    Jarrow Brewing Company Jobling's Swinging Gibbett /m/0dlfhxy 4.1 Jarrow Brewing Company
    Vale VPA /m/0dkfs82 Vale
    Darwin Brewery Hop Drop /m/0dl8hr3 5.3 Darwin Brewery
    Franziskaner Hefe-Weisse Hell /m/0djwwtd Weiss 1516 5.0
    Rip Tide /m/0b68kjd Stout 8.0 1074.0 65.0 BrewDog /m/0b68m5h,/m/0b68lsj,/m/0b68m5q,/m/0b68lsq
    John Smiths /m/03gnvjj Bitter 1847 4.0 United Kingdom
    Dark Star Critical Mass /m/0dl8hhr 7.8 Dark Star
    Colorado Caium /m/0djxh7m Pilsener
    Nethergate Umbel Magna /m/0dkfscl Nethergate brewery
    Abbey Ales Black Friar /m/0djv0xl Bitter Abbey Ales Brewery
    Strangford Lough Barelegs Brew /m/04dqczw 4.5 Strangford Lough Republic of Ireland /m/04dr37j


  2. #2
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    472
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: HOW TO PARSE A TEXT FILE

    I'm not really sure I understand the problem - AFAICS the fields have to have some recognisable delimiters if they are to be distinguished, but you seem to be saying they won't...

    If that's the case, how do you tell where one field ends and the next begins?
    Last edited by dlorde; May 27th, 2011 at 08:09 AM.

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: HOW TO PARSE A TEXT FILE

    If the first line of your data display is the model for the data lines to follow, the fields appear to be separated by a space and there are more than 3 fields.
    The following lines appear to have the fields separated by / and there are only 3 fields.

    Because you have posted the data as text input, the forum formatter has wrapped the lines and it is impossible to see the original lines.

    Makes no sense.

  5. #5
    Junior Member
    Join Date
    May 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: HOW TO PARSE A TEXT FILE

    check for missing semicolons...

Similar Threads

  1. Text file to text area and Radiobuttons?
    By donaldmax in forum What's Wrong With My Code?
    Replies: 9
    Last Post: May 27th, 2011, 04:45 AM
  2. Replies: 8
    Last Post: March 25th, 2011, 02:34 PM
  3. Read a text file and parse the contents of file
    By HelloAll in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: March 3rd, 2011, 05:47 AM
  4. [SOLVED] parse txt file
    By maliv in forum File I/O & Other I/O Streams
    Replies: 16
    Last Post: November 17th, 2010, 03:54 PM
  5. java program to copy a text file to onother text file
    By francoc in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: April 23rd, 2010, 03:10 PM