Find the answer to your Linux question:
Results 1 to 6 of 6
i currently have a shell script in which i am trying to pass a txt file, by lines into a sql script. the txt file looks like this: filename.ext : ...
  1. #1
    Just Joined!
    Join Date
    Jul 2007
    Posts
    14

    bash to sql

    i currently have a shell script in which i am trying to pass a txt
    file, by lines into a sql script. the txt file looks like this:

    filename.ext : category PossiblyAnotherCategory
    filename2.ext : category PossiblyAnotherCategory
    ...

    For each line, set each word as a variable and pass it to the sql
    script..is this possible?

  2. #2
    Linux Guru sdousley's Avatar
    Join Date
    Feb 2004
    Posts
    1,789
    Quote Originally Posted by joshboski View Post
    i currently have a shell script in which i am trying to pass a txt
    file, by lines into a sql script. the txt file looks like this:

    filename.ext : category PossiblyAnotherCategory
    filename2.ext : category PossiblyAnotherCategory
    ...

    For each line, set each word as a variable and pass it to the sql
    script..is this possible?
    Best way to do this would be through awk. something like this:

    Code:
    variable1=`echo $line | awk '{print $1'}`
    Would set the variable "variable1" to the first word on the line eg. filename.ext filename2.ext. Put this in a loop along with the creation of the SQL statement, and this should give you a good starting ground.
    "I am not an alcoholic, alcoholics go to meetings"
    Registered Linux user = #372327

  3. #3
    Just Joined!
    Join Date
    Jul 2007
    Posts
    14
    thank you much

  4. #4
    Just Joined!
    Join Date
    Jul 2007
    Posts
    14
    okay I am using an API called set_attribute which uses the parameters
    ID and CATEGORYID... and I am taking what I have in this file, using
    the file name to find the ID number, then I am going to look up the
    categories number by the name of the category. It basically is
    programatically applying categories to those files

  5. #5
    Linux Guru sdousley's Avatar
    Join Date
    Feb 2004
    Posts
    1,789
    In that case, might i suggest a slightly different method. If you had a lookup table for the "categories" and then a linking table that sits between the categories and files table, you could lay the text file out like:

    Code:
    filename.ext category
    filename.ext another_category
    filename2.ext yet_another_category
    filename2.ext another_category
    I suggest this since it seems that you dont know for certain how many categories a file may be attributed to, therefore the linking table means you dont need to create a new field on the files table to add an extra category, since with this, a lot of the fields will be blank.
    "I am not an alcoholic, alcoholics go to meetings"
    Registered Linux user = #372327

  6. #6
    Just Joined!
    Join Date
    Jul 2007
    Posts
    14
    now I am going to be attempting to use sql*loader

Posting Permissions

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