DBAsupport.com Forums - Powered by vBulletin
Results 1 to 3 of 3

Thread: grep the tnsnames.ora

  1. #1
    Join Date
    Oct 2000
    Posts
    250

    grep the tnsnames.ora

    Dear all,
    I have a unix command - grep to embed into my shell script program to find the service name in tnsnames.ora

    For example,
    mydb =
    (DESCRIPTION =
    (ADDRESS = (PROTOCOL= TCP)(Host= myhost)(Port= 1521))
    (CONNECT_DATA = (SID = testdb))
    )
    mydb2 =
    (DESCRIPTION =
    (ADDRESS = (PROTOCOL= TCP)(Host= myhost2)(Port= 1521))
    (CONNECT_DATA = (SID = testdb2))
    )

    how to grep the value mydb and mydb2 out and assign to a file ?

    Thanks

  2. #2
    Join Date
    May 2002
    Posts
    2,645
    Do a "man grep" at your UNIX prompt.

    You can do grep "some string" file_name > search.file

  3. #3
    Join Date
    Dec 2003
    Posts
    11
    Hi,

    If you know the exact number of rows(e.g. 4) following mydb string in your tnsnames.ora file(s) you can write:

    grep -A4 -h -E "mydb.*=" tnsnames.ora > file.out

    -A4 = + 4 rows after the hit
    -h = no header
    -E = extended regular expression

    It works in GNU grep.

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