Find the answer to your Linux question:
Results 1 to 5 of 5
i need a simple text parser which can parse a data file created by a softwre so that i can export it to my mysqldb,, datafile created as one record ...
  1. #1
    Just Joined!
    Join Date
    Jul 2008
    Posts
    3

    Question need a text parser

    i need a simple text parser which can parse a data file created by a softwre so that i can export it to my mysqldb,, datafile created as one record per line with different number of fields.

    e.g datafile contains following.

    a=1, b=3, c=4
    a=1, c=55, d=abcd
    a=5, b=hello, c=99, d=help


    now i want to parse them as
    1,3,4
    1,55,abcd
    5,hello,99,help

    i want to remove field name and make data as comma seperated so that i can export them to my db. or anyother way to export these fields to mysql where field names are same as a,b,c,d.
    a,b,c and d are fields.

  2. #2
    Linux Guru coopstah13's Avatar
    Join Date
    Nov 2007
    Location
    NH, USA
    Posts
    3,149
    look on the web for awk tutorials, you should find what you need

  3. #3
    Just Joined!
    Join Date
    Jul 2008
    Posts
    3
    I tred awk but i dont know how to use multi dimentioal arrays for split. I can split single value e.g a=1 but dont knw how to with multiple values in single record.

    any sugession ?

  4. #4
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    A simple sed line should do:

    Code:
    sed -e 's/ *[a-zA-Z]*=//g' filename.txt

  5. #5
    Just Joined!
    Join Date
    Jul 2008
    Posts
    3
    i got rid of the left side and got the results with awk and sed using

    sed 's/[^,]*=//g'

    but one poblem. On monotor it displays correclty but when at the end i try ti put them in a file using >> filename , there i am getting "\" after every field and that file 'filename'.

    eg.

    12\,hello\,99
    2\,22\,abcd

    how to remove the trailing '\'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...