Awk to format the files .ora (listener.ora, tnsnames.ora, etc)

Tired of formatting the tnsnames.ora to make it more readable, I have taken the nice awk examples from Jeremy Schneider: https://ardentperf.com/2008/11/28/parsing-listenerora-with-awk-and-sed/ and created a function to format all files .ora (lisp-like config files).

Example, before:

and after:

The AWK script:

I have included the function in the COE github repo. More functions to come (hopefully).

Ludo

The following two tabs change content below.

Ludovico

Principal Product Manager at Oracle
Ludovico is a member of the Oracle Database High Availability (HA), Scalability & Maximum Availability Architecture (MAA) Product Management team in Oracle. He focuses on Oracle Data Guard, Flashback technologies, and Cloud MAA.

4 thoughts on “Awk to format the files .ora (listener.ora, tnsnames.ora, etc)

  1. Hi Ludovico – thanks for the great information. I’ve got it running (mostly), but I’m not an awk expert and occasionally run into issues if there are comments in the listener.ora.
    Example lines:
    LISTENER_SCAN1=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER_SCAN1)))) # line added by Agent
    ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER_SCAN1=ON # line added by Agent
    Any suggestion on tweaking the awk code to handle ‘comments’ that aren’t at the beginning of the line?
    Thanks again, best regards – Scott C.

    • Hi Pepe, it’s in the comments in the head of the code…

      # you can source this function in bash and use it like: # cat $TNS_ADMIN/listener.ora | tidy_dotora

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.