troubleshooting Question

need help with awk or sed writing a bash script to find a delete an object in a flat database file

Avatar of Dooglave
Dooglave asked on
LinuxShell ScriptingRegular Expressions
9 Comments1 Solution701 ViewsLast Modified:
I need help removing the following text from a file. It's an object in a flat file database. I need to find     : (VSXSERVER_VSNAME      and delete the contents from : to the closing bracket )

I usually do this in vi by putting the cursor on the : and then hitting d then %

This datbase has a number of other objects that I want to leave alone.

I want to define VSXSERVER_VSNAME as an enviroment variable so I can create a loop to run through a list object names.

I have this script that I used to delete the contents between ( and ) for :certificates but I'm not familar enough with awk to modify it to complete this task.

please help!

cat $FWDIR/conf/objects_5_0.C | awk 'BEGIN {c=0};  /:certificates \(\)/ {print;next}; /:certificates \(/ {c=1;print;next}; c>0 &&  /\(/ {c++}; c>0 && /\)/ {c--}; c<=0 {print}' >> $FWDIR/conf/objects_5_0.C.new




: (VSXSERVER_VSNAME
                  :AdminInfo (
                        :chkpf_uid ("{15886D8F-31B2-491A-BE18-D63DE2AA8599}")
                        :ClassName (vs_cluster_member)
                        :table (network_objects)
                        :LastModified (
                              :Time ("Sun Dec 18 08:08:07 2011")
                              :last_modified_utc (1324195687)
                              :By (localhost)
                              :From (GUICLIENT)
                        )
                        :icon ("NetworkObjects/vsx/vs_member")
                        :name (VSXSERVER_VSNAME)
                  )
                  :certificates ()
                  :edges ()
                  :free_fields ()
                  :interfaces (
                        :0 (
                              :AdminInfo (
                                    :chkpf_uid ("{9115D02E-94C6-4514-9DA5-2D3E6A61E0BF}")
                                    :ClassName (interface)
                              )
                              :edges ()
                              :bandwidth ()
                              :comments ()
                              :description ()
                              :dual_wan (false)
                              :dynamic_ip (false)
                              :ifindex (0)
                              :ip_pool_allocation ()
                              :ipaddr (192.168.1.1)
                              :ipv6_address ()
                              :ipv6_prefix (64)
                              :monitored_by_cluster (false)
                              :multicast_enforcement ()
                              :netmask (255.255.255.240)
                              :officialname (wrp1536)
                              :antispoof (true)
                              :netaccess (
                                    :AdminInfo (
                                          :chkpf_uid ("{DA3E1225-98EE-4E44-96F8-569056DE6710}")
                                          :ClassName (netaccess)
                                    )
                                    :access (undefined)
                                    :allowed ()
                                    :dmz (false)
                                    :enable_overlapping_nat (false)
                                    :force_policy (true)
                                    :internal_type (undefined)
                                    :leads_to_internet (false)
                                    :log (log)
                                    :monitor_anti_spoofing (false)
                                    :overlap_nat_dst_ipaddr ()
                                    :overlap_nat_netmask (255.255.255.0)
                                    :overlap_nat_src_ipaddr ()
                                    :perform_anti_spoofing (false)
                              )
                              :security (
                                    :AdminInfo (
                                          :chkpf_uid ("{9115D02E-94C6-4514-9DA5-2D3E6A61E0BF}")
                                          :ClassName (interface_security)
                                    )
                              )
                              :security_zone ()
                              :shared (true)
                              :vpn_trusted (false)
                        )
                        :1 (
                              :AdminInfo (
                                    :chkpf_uid ("{117509D3-EC8B-4F95-9DAB-8C5BFCE2BAC9}")
                                    :ClassName (interface)
                              )
                              :edges ()
                              :bandwidth ()
                              :comments ()
                              :description ()
                              :dual_wan (false)
                              :dynamic_ip (false)
                              :ifindex (1)
                              :ip_pool_allocation ()
                              :ipaddr (192.168.196.18)
                              :ipv6_address ()
                              :ipv6_prefix (64)
                              :monitored_by_cluster (false)
                              :multicast_enforcement ()
                              :netmask (255.255.255.240)
                              :officialname (Lan1.210)
                              :antispoof (true)
                              :netaccess (
                                    :AdminInfo (
                                          :chkpf_uid ("{1A1DA713-7619-4CBE-B264-81C3FB8BD345}")
                                          :ClassName (netaccess)
                                    )
                                    :access (undefined)
                                    :allowed ()
                                    :dmz (false)
                                    :enable_overlapping_nat (false)
                                    :force_policy (true)
                                    :internal_type (undefined)
                                    :leads_to_internet (false)
                                    :log (log)
                                    :monitor_anti_spoofing (false)
                                    :overlap_nat_dst_ipaddr ()
                                    :overlap_nat_netmask (255.255.255.0)
                                    :overlap_nat_src_ipaddr ()
                                    :perform_anti_spoofing (false)
                              )
                              :security (
                                    :AdminInfo (
                                          :chkpf_uid ("{117509D3-EC8B-4F95-9DAB-8C5BFCE2BAC9}")
                                          :ClassName (interface_security)
                                    )
                              )
                              :security_zone ()
                              :shared (true)
                              :vpn_trusted (false)
                        )
                        :2 (
                              :AdminInfo (
                                    :chkpf_uid ("{B8642EC1-CE35-434B-8B6F-20935B16ED49}")
                                    :ClassName (interface)
                              )
                              :edges ()
                              :bandwidth ()
                              :comments ()
                              :description ()
                              :dual_wan (false)
                              :dynamic_ip (false)
                              :ifindex (2)
                              :ip_pool_allocation ()
                              :ipaddr (192.168.1.2)
                              :ipv6_address ()
                              :ipv6_prefix (64)
                              :monitored_by_cluster (false)
                              :multicast_enforcement ()
                              :netmask (255.255.255.240)
                              :officialname (Lan1.280)
                              :antispoof (true)
                              :netaccess (
                                    :AdminInfo (
                                          :chkpf_uid ("{79A2A5FF-29FC-4F5A-9A8D-4066EB98D6E2}")
                                          :ClassName (netaccess)
                                    )
                                    :access (undefined)
                                    :allowed ()
                                    :dmz (false)
                                    :enable_overlapping_nat (false)
                                    :force_policy (true)
                                    :internal_type (undefined)
                                    :leads_to_internet (false)
                                    :log (log)
                                    :monitor_anti_spoofing (false)
                                    :overlap_nat_dst_ipaddr ()
                                    :overlap_nat_netmask (255.255.255.0)
                                    :overlap_nat_src_ipaddr ()
                                    :perform_anti_spoofing (false)
                              )
                              :security (
                                    :AdminInfo (
                                          :chkpf_uid ("{B8642EC1-CE35-434B-8B6F-20935B16ED49}")
                                          :ClassName (interface_security)
                                    )
                              )
                              :security_zone ()
                              :shared (true)
                              :vpn_trusted (false)
                        )
                  )
                  :Machine_weight (1)
                  :NAT ()
                  :accessible_from_smc (true)
                  :add_adtr_rule (false)
                  :color (black)
                  :comments ()
                  :connection_state (initialized)
                  :ics_update_supported (false)
                  :ip_pool_nat (false)
                  :ip_pool_office_mode (false)
                  :ip_pool_securemote_allocation_name ()
                  :ipaddr (0.0.0.0)
                  :is_bridge (false)
                  :junction (false)
                  :mgmt_ip (10.0.0.251)
                  :om_ippool ()
                  :owner ()
                  :sic_identifier (
                        :AdminInfo (
                              :chkpf_uid ("{6232F2DE-F76D-1180-9785-0A6015905355}")
                              :ClassName (gw_sic_identifier)
                        )
                        :id_type (ip_addr)
                        :id_value ()
                  )
                  :sic_name ("CN=VSXSERVER_VSNAME,O=MAIL-TEST.web.mgmtserver.org.selse4")
                  :type (cluster_member)
                  :vs_cluster_member (true)
            )
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 9 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros