unix script, help
DBAsupport.com Forums - Powered by vBulletin
Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: unix script, help

Hybrid View

  1. #1
    Join Date
    Nov 2000
    Posts
    245

    I have a text file looks like:
    lang_tab id number
    lang_tab name varchar2(10)
    lang_tab suffix varchar2(10)

    does anyone know/have a script to create output like:
    an array with "," delimiter. e.g. id,name,sufix

    thanks in advance

  2. #2
    Join Date
    Aug 2001
    Posts
    64
    it looks like the file is space delimited, you can use:
    cat file_name | awk '{print $1,","$2,","$3}'


  3. #3
    Join Date
    Oct 2000
    Location
    Saskatoon, SK, Canada
    Posts
    3,925
    #!/bin/sh


    $ORACLE_HOME/bin/sqlplus -S usrename/password@servicename << EOF

    set heading off
    set pagesize 1000
    set arraysize 100
    spool filename

    select id||","||name||","||suffix
    from table_name;

    spool off
    EOF

    exit


    -----------------------

    Sam
    Thanx
    Sam



    Life is a journey, not a destination!


  4. #4
    Join Date
    Nov 2000
    Posts
    245
    sorry, I did not make it clear. I want only display the 2nd field of each row and concated into a line with "," as delimiter.

    the text file looks like 3xn

    lang_tab id number
    lang_tab name varchar2(10)
    lang_tab suffix varchar2(10)
    : : :
    lang_tab user varchar2(16)

    the output I want to be an array

    id,name,suffix

    thanks



  5. #5
    Join Date
    Oct 2000
    Location
    Saskatoon, SK, Canada
    Posts
    3,925
    Is your text file is fixed field format or variable filed format.

    Sam
    Thanx
    Sam



    Life is a journey, not a destination!


  6. #6
    Join Date
    Jul 2000
    Posts
    521
    post a sample data and how you want it to become.
    You might be able to do it in 'vi' itself.
    svk

  7. #7
    Join Date
    Nov 2000
    Posts
    245
    I spool
    select TABLE_NAME,column_name,DATA_TYPE from user_tab_columns;
    to a text file:

    This is the sample data which spooled from sqlplus

    cust_tab custid number
    cust_tab custname varchar2(20)
    cust_tab ...
    : : :
    cust_tab user varchar2(16)
    lang_tab langid number
    lang_tab name varchar2(10)
    lang_tab suffix varchar2(10)
    : : :
    lang_tab user varchar2(16)

    now, I need to create a string which contains all column name for each table.

    output should be:

    custid,custname,descption,..user
    langid,langname,suffic,..user


  8. #8
    Join Date
    Jul 2000
    Posts
    521
    Confusion !!

    The SQL query that you have mentioned should create one line records (with proper linesize). The you can use the awk option you that has been posted earlier.

    Why are you saying that you are getting one column per line ?
    svk

  9. #9
    Join Date
    Nov 2000
    Posts
    245

    I guess I still not make it clear enough. sorry.

    Say I have 2 table cust_tab and lang_tab
    cust_tab contains 5 columns: custid, custname, custaddr, custphone, updateuser.
    lang_tab contain 4 columns: langid, langname, langdesc, updateuser.

    I want create a list column name for each table. (one line per table, use "," to seperate columns)
    so the output will be

    custid, custname, custaddr, custphone, updateuser
    langid, langname, langdesc, updateuser
    ----
    I assume I should spool them into a text file
    the text file will be:

    cust_tab custid number
    cust_tab custname varchar2(20)
    cust_tab custaddr varchar2(40)
    cust_tab custphone varchar2(16)
    cust_tab updateuser varchar2(16)
    lang_tab langid number
    lang_tab langnam varchar2(30)
    lang_tab langdesc varchar2(30)
    lang_tab updateuser varchar2(16)


    then AWK to lines. how?

    thanks

  10. #10
    Join Date
    Oct 2000
    Location
    Saskatoon, SK, Canada
    Posts
    3,925
    If you need the SQL query to be in the text file format, go ahead and use the shell script what I had posted in there with your query parameters in place.

    I still don't get what you are looking for???

    Explain the purpose/need step by step.

    Sam
    Thanx
    Sam



    Life is a journey, not a destination!


Posting Permissions

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


Click Here to Expand Forum to Full Width