linux - delete lines based on number of brackets? -
i trying find best way replace text in file called listener.ora oracle. looking replace "sid_list_listener_orcl" entry else... have couple of things can go wrong here want avoid...
first can see entry can either entry#1 or entry#2, first 1 has "sdu=" entry, while second 1 dont...do note file either have entry#1 or entry#2 , not both @ same time(at least not in our environment).
second, thinking find of "sid_list_listener_orcl" , delete 6 or 7 lines there, entry varies (sdu= in 1 , not in other) dont think idea...
next thing, no matter can come might find environment might have lets 2 more lines in entry script break or cause other error....so nice have work these 2 entry , else might encounter in future...one important thing can think of is, no matter how many lines have 6, 7, 9 or 9 have exact number start , close brackets{ () }... starting "(sid_list ="
i know want replace , have part worked out struggling how delete existing lines
### entry #1 sid_list_listener_orcl = (sid_list = (sid_desc = (sdu = 32768) (sid_name = orcl) (oracle_home = /oracle/orcl/11264) ) ) ## entry #2 sid_list_listener = (sid_list = (sid_desc = (sid_name = orcl) (oracle_home = /oracle/orcl/11264) ) )
the full listener.ora file typically this...
listener_orcl = (description_list = (description = (address_list = (address = (protocol = tcp) (host = hostname) (port = 1578) ) ) ) ) startup_wait_time_listener_orcl = 0 connect_timeout_listener_orcl = 10 trace_level_listener_orcl = off sid_list_listener_orcl = (sid_list = (sid_desc = (sdu = 32768) (sid_name = orcl) (oracle_home = /oracle/orcl/11204) ) )
this delete content matching parenthesis on same line. i'm not sure that's problem though.
$ sed '/(.*)/d' file
will print
sid_list_listener_orcl = (sid_list = (sid_desc = ) ) ## entry #2 sid_list_listener = (sid_list = (sid_desc = ) )
update full file.
for it's better switch awk
power.
$ awk -v rs= -f"\n" '!/sid_list_listener/{print} /sid_list_listener/{for(i=1;i<=nf;i++) if($i!~/\(.*\)/) print $i}' listener.ora
will delete matched parenthesis in required context.
listener_orcl = (description_list = (description = (address_list = (address = (protocol = tcp) (host = hostname) (port = 1578) ) ) ) ) startup_wait_time_listener_orcl = 0 connect_timeout_listener_orcl = 10 trace_level_listener_orcl = off sid_list_listener_orcl = (sid_list = (sid_desc = ) )
update 2 delete full record
$ awk -f"\n" -v rs= '/sid_list_listener/{sub("sid_list_listener.*","")}1' listener.ora listener_orcl = (description_list = (description = (address_list = (address = (protocol = tcp) (host = hostname) (port = 1578) ) ) ) ) startup_wait_time_listener_orcl = 0 connect_timeout_listener_orcl = 10 trace_level_listener_orcl = off
Comments
Post a Comment