#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    8
    Rep Power
    0

    Split text file into multiple text file


    Trying to write Java/C/C++/PHP code to choose text file from computer and split into multiple text file based on field information

    Text file select:

    "First Name","Last Name","Address Line 1","Address Line 2","City","State","ZIP Code","IM Barcode","Sort Position","Tray Number"
    "Stephen","Hight","105 Thurman St","","Carrollton","GA","30117-1955","ADADFTFATTTDADADDFFTAFFFTDDTADDFTFDAFAATDFA AATFATDTFTAAFFAADAFFDT",1,1
    "Kimberly","Kendall","104 Thurman St","","Carrollton","GA","30117-1956","DAAFATDATAFTADDDTTTTADTFATFFDDFTAFDDATDDAAD FTATADADFDTFDAFDDATFDA",2,1
    "James","Boles","108 Thurman St","","Carrollton","GA","30117-1956","DADFDDTFDAFADTFTATADTTDTFATAAFADTATDFTTFAAF TDDFDAFATDTTDTFTFDTTTT",3,1
    "Douglas","Kelley","110 Thurman St","","Carrollton","GA","30117-1956","TFTTTAATDFDAFTDFADFDAFFTTFATATDAAFAATTAFDTD ATFAAFDFAFFTTDTDFFAADD",4,1
    "Christine","Creel","408 Old Mill Dr","","Carrollton","GA","30117-6313","TFDDDTDAFDFFFATDATADFFDAFFTAATTAFDFFTDADDTF TTAFAFATFDATDFTTFTATFF",989,2
    "Elaine","Hobson","410 Old Mill Dr","","Carrollton","GA","30117-6313","DTFFDTAFAFDTADTDDFAFFTDFDTTTDTATDFTDAFTATFA DAAFADDTATTFFTDDTDDFDD",990,2
    "Erica","Tisinger","412 Old Mill Dr","","Carrollton","GA","30117-6313","DFFAAFTDTTADDDATDATATFAFDDFADADFDATTFFAFDDT FFADDTAFTAADTDFDAFADTF",991,2
    "Brandon","Peterson","418 Old Mill Dr","","Carrollton","GA","30117-6313","FTADAAATDATDFTTDTFDFFTTDTTFDTDDDTFAFFATATDF DAADFTDTATDFATAFDADFTT",992,2
    "Robert","Ballard","425 Old Mill Dr","","Carrollton","GA","30117-6314","TFATFFDTADADDAATFTTADFFTFFDFAFAADAAFTAAFDFD FDAFTTFATDFATFFFFTAFAD",993,2
    "Susan","Newbern","429 Old Mill Dr","","Carrollton","GA","30117-6314","AADDFFFFFATADFDTDFFDDDDFTTDTAAFDTADAFDDDAFD ADTFDFDFDDTDTAATTATAAA",994,2
    "M","Motes","431 Old Mill Dr","","Carrollton","GA","30117-6314","TATDAAFTFTTFADFDDFAFATDDAATDADFDFFFTTADDATT AAAFAATAFADDTAFTTFTTFT",995,3
    "Charles","Willis","114 Old Mill Ct","","Carrollton","GA","30117-6317","AFDDTATAADAFFDFFTAATAFTTADDFFDTFFFFDTTADDTT DATDATFFAAAFTFFADFATAD",996,3
    "Nancy","Fox","124 Old Mill Ct","","Carrollton","GA","30117-6317","DFDTATTFFDAAADDDTAATFFFTDFFTFTFFDFDFTFADDDF FADDFDFTAFFADFADTTATFA",997,3
    "Linda","Smith","126 Old Mill Ct","","Carrollton","GA","30117-6317","ATFTDAFTDTTDFTTDAFFDFTTDDADADTDTTFAFFDDATTF TAFAFFDFFADDATTTAFDDTA",998,3
    "Lance","Hatfield","112 Orion Ter","","Carrollton","GA","30117-6318","TDFAFADATAAFFFADATAAFATDTFTTTTAFFFTTFDATDAD ATDAFAFAAFFTAFDFTAFDAA",999,4
    "Dr. Lona","Bibbs","1741 Newnan Crossing Blvd E","","Newnan","GA","30265-1599","TFFTDDTADADTFDFFATFDTTTDAFFTDTDTAFTATFTAADF TFAFADTFAATFTTFTDTTDFT",1000,4


    Split text file:
    split text file1)

    Filename+traynumber 1:

    "First Name","Last Name","Address Line 1","Address Line 2","City","State","ZIP Code","IM Barcode","Sort Position","Tray Number"
    "Stephen","Hight","105 Thurman St","","Carrollton","GA","30117-1955","ADADFTFATTTDADADDFFTAFFFTDDTADDFTFDAFAATDFA AATFATDTFTAAFFAADAFFDT",1,1
    "Kimberly","Kendall","104 Thurman St","","Carrollton","GA","30117-1956","DAAFATDATAFTADDDTTTTADTFATFFDDFTAFDDATDDAAD FTATADADFDTFDAFDDATFDA",2,1
    "James","Boles","108 Thurman St","","Carrollton","GA","30117-1956","DADFDDTFDAFADTFTATADTTDTFATAAFADTATDFTTFAAF TDDFDAFATDTTDTFTFDTTTT",3,1
    "Douglas","Kelley","110 Thurman St","","Carrollton","GA","30117-1956","TFTTTAATDFDAFTDFADFDAFFTTFATATDAAFAATTAFDTD ATFAAFDFAFFTTDTDFFAADD",4,1

    Split Text file 2)
    Filename+traynumber 2:

    "First Name","Last Name","Address Line 1","Address Line 2","City","State","ZIP Code","IM Barcode","Sort Position","Tray Number"
    "Christine","Creel","408 Old Mill Dr","","Carrollton","GA","30117-6313","TFDDDTDAFDFFFATDATADFFDAFFTAATTAFDFFTDADDTF TTAFAFATFDATDFTTFTATFF",989,2
    "Elaine","Hobson","410 Old Mill Dr","","Carrollton","GA","30117-6313","DTFFDTAFAFDTADTDDFAFFTDFDTTTDTATDFTDAFTATFA DAAFADDTATTFFTDDTDDFDD",990,2
    "Erica","Tisinger","412 Old Mill Dr","","Carrollton","GA","30117-6313","DFFAAFTDTTADDDATDATATFAFDDFADADFDATTFFAFDDT FFADDTAFTAADTDFDAFADTF",991,2
    "Brandon","Peterson","418 Old Mill Dr","","Carrollton","GA","30117-6313","FTADAAATDATDFTTDTFDFFTTDTTFDTDDDTFAFFATATDF DAADFTDTATDFATAFDADFTT",992,2
    "Robert","Ballard","425 Old Mill Dr","","Carrollton","GA","30117-6314","TFATFFDTADADDAATFTTADFFTFFDFAFAADAAFTAAFDFD FDAFTTFATDFATFFFFTAFAD",993,2
    "Susan","Newbern","429 Old Mill Dr","","Carrollton","GA","30117-6314","AADDFFFFFATADFDTDFFDDDDFTTDTAAFDTADAFDDDAFD ADTFDFDFDDTDTAATTATAAA",994,2

    Split text file 3)
    Filename+traynumber 3:

    "First Name","Last Name","Address Line 1","Address Line 2","City","State","ZIP Code","IM Barcode","Sort Position","Tray Number"
    "M","Motes","431 Old Mill Dr","","Carrollton","GA","30117-6314","TATDAAFTFTTFADFDDFAFATDDAATDADFDFFFTTADDATT AAAFAATAFADDTAFTTFTTFT",995,3
    "Charles","Willis","114 Old Mill Ct","","Carrollton","GA","30117-6317","AFDDTATAADAFFDFFTAATAFTTADDFFDTFFFFDTTADDTT DATDATFFAAAFTFFADFATAD",996,3
    "Nancy","Fox","124 Old Mill Ct","","Carrollton","GA","30117-6317","DFDTATTFFDAAADDDTAATFFFTDFFTFTFFDFDFTFADDDF FADDFDFTAFFADFADTTATFA",997,3
    "Linda","Smith","126 Old Mill Ct","","Carrollton","GA","30117-6317","ATFTDAFTDTTDFTTDAFFDFTTDDADADTDTTFAFFDDATTF TAFAFFDFFADDATTTAFDDTA",998,3

    Split text file 4)
    Filename+traynumber 4:

    "First Name","Last Name","Address Line 1","Address Line 2","City","State","ZIP Code","IM Barcode","Sort Position","Tray Number"
    "Lance","Hatfield","112 Orion Ter","","Carrollton","GA","30117-6318","TDFAFADATAAFFFADATAAFATDTFTTTTAFFFTTFDATDAD ATDAFAFAAFFTAFDFTAFDAA",999,4
    "Dr. Lona","Bibbs","1741 Newnan Crossing Blvd E","","Newnan","GA","30265-1599","TFFTDDTADADTFDFFATFDTTTDAFFTDTDTAFTATFTAADF TFAFADTFAATFTTFTDTTDFT",1000,4


    Like these, Anyone has an idea how can i write a java code for this??
    Please help me. I am beginners in Java/C/C++/PHP code. My professor told me that simple.
    Please help me guys!!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,600
    Rep Power
    595
    What have you tried? What is the split criteria?
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    8
    Rep Power
    0
    Well Actually I am trying to write code to
    choose text file and split in multiple text file based on that field tray number.

    Please help me. I was trying to write that code in Java. I know first part how to choose text file from computer and read that file. but 2nd part i got confused create multiple text files by field name traynumber. Please help. can you help with Java code??
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,600
    Rep Power
    595
    This is a PHP forum. I've requested this be moved to the Java forum.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  8. #5
  9. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    Welcome to the Java Forum.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    8
    Rep Power
    0
    ohh ok thanks man
  12. #7
  13. Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    May 2004
    Location
    Superior, CO, USA
    Posts
    2,418
    Rep Power
    1713
    Originally Posted by gw1500se
    What have you tried? What is the split criteria?
    The question that gw150se asked is still valid and would be regardless of the programming language. What are the requirements? It looks like the very last number in the line changes but it isn't clear if that is the only thing.

    We're willing to help but, regardless of language implementation, you should have an idea of how you would solve the problem.
  14. #8
  15. Recovering Intellectual
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2006
    Location
    Orange County, CA
    Posts
    1,306
    Rep Power
    785
    1. Read in the file
    2. split the first line into an array on the comma and store as 'field names'
    3. split the remaining lines into an array on the comma and store as values
    4. using the first array and the subsequent arrays find the last field and get the value (you dont have to use the first array you can just assume what the value is by its index)
    5. Using the the last field value and the input value open a new file and write the contents of the arrays matching the last field value
    6. Test
    7. Repeat 1-6 if required

    OR you could just say screw all that and stream edit the #%$* into some files using bash and awk - but id say just use java for now
    Last edited by Matt1776; April 18th, 2013 at 06:25 PM.
    Bugs that go away by themselves come back by themselves
    Beware - your loyalty will not be rewarded
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    8
    Rep Power
    0
    import javax.swing.JFileChooser;
    import javax.swing.filechooser.FileNameExtensionFilter;

    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileReader;
    import java.sql.Connection;

    public class choosetextfile11 {

    public static void main(String[] args)throws Exception {

    JFileChooser chooser = new JFileChooser();
    FileNameExtensionFilter filter = new FileNameExtensionFilter ("Text/Java files", "txt", "java");
    chooser.setFileFilter(filter);

    int returnVal = chooser.showOpenDialog(null);

    if(returnVal == JFileChooser.APPROVE_OPTION) {
    File f = chooser.getSelectedFile();
    BufferedReader br = new BufferedReader (new FileReader(f));
    String st = "";
    while((st = br.readLine()) != null) {
    System.out.println(st);
    }

    }

    }

    }


    ----------

    this is the code tht i wrote.. How can i write the code for just look over the traynumber field..
  18. #10
  19. Recovering Intellectual
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2006
    Location
    Orange County, CA
    Posts
    1,306
    Rep Power
    785
    I already gave you the keys to the kingdom.

    Look up arrays, associative arrays, string splitting, etc. Google is your friend. If you've done this much and managed to get a GUI (?!!!) going here you should be able to finish. All your doing is parsing a CSV file.

    At this point you should be coming back with debugging questions
    Bugs that go away by themselves come back by themselves
    Beware - your loyalty will not be rewarded
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    8
    Rep Power
    0

    Talking


    I know the part..
    choose text file and read that..
    second part is hard for me actually..
    look over the traynumber field and look how many times tray number changed.. and create that many times text files and name it that filetraynumber1,2.....

    and First line is fields like header so it should be in every text file and last thing is split that...

    First part is easy but second and third lol hard for me. I am beginners.. soo...

    please help me!! Thanks in advanced..
  22. #12
  23. Recovering Intellectual
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2006
    Location
    Orange County, CA
    Posts
    1,306
    Rep Power
    785
    This is exactly what everyone has been saying to you - your requirements are unclear. The steps I outlined were based on the *assumption* that all you needed to do was to break up the data into files based on the tray number. If you need to do something with the number of times the file changed then that adds a layer of complexity - this must be explained.

    Take your requirements and list out what would need to be done as I have done for you; do for yourself. This is programatic and critical thinking has nothing to do with programming yet. Get your requirements.

    [EDIT] I dont see any information about the number of times the file changed I just see a tray number. if you want the lines within each result-tray#.ext file then just sort the results on the second to last field when you write the file. Google is your friend.
    Last edited by Matt1776; April 18th, 2013 at 08:10 PM.
    Bugs that go away by themselves come back by themselves
    Beware - your loyalty will not be rewarded
  24. #13
  25. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348

IMN logo majestic logo threadwatch logo seochat tools logo