Skip to main content
Changed question there is nothing wrong with hte code in question
Link

Removing specific lines with sed from file using bash script

Changed question there is nothing wrong with hte code in question
Source Link

I have a code like this to parse zoneinput file and remove whatever its told to remove:that contains DNS zone entries

#!/bin/bash

for; ARGwhatever.foo in[000000]
$ORIGIN "$@"whatever.foo.
do$TTL 8400
@    sed -i "/^\(something-\|other-\|\)${ARG}[[:space:]]\+IN[[:space:]]\+A/d" /etc/nsd/zones/domainIN      SOA     ns1.comwhatever.zonefoo.      admin.whatever.foo. (
done2017101913 ; serial number

And it works great for removing lines like

                    21600                    ; refresh
                    8400                     ; retry
                    1209600                 ; expire
                    8400                    ; ttl
                    )

xxx           IN    A    000.000.000.000
something-xxx IN    A    000.000.000.000
other-xxx     IN    A    000.000.000.000

Now I get a subdomain that I need to remove say else.xxx so entry is like:

else.xxx      IN    A    000.000.000.000

yyy           IN    A    000.000.000.001
something-yyy IN    A    000.000.000.001
other-yyy     IN    A    000.000.000.001
else.yyy      IN    A    000.000.000.001

How do I tried modifying the script like thisremove for example entries that belong to xxx subdomain domain?

Output should be

sed; -iwhatever.foo "/^\[000000]
$ORIGIN whatever.foo.
$TTL 8400
@       IN      SOA     ns1.whatever.foo.      admin.whatever.foo. (else
2017101913 ; serial number
                    21600                    ; refresh
                    8400                     ; retry
                    1209600                 ; expire
                    8400                    ; ttl
                    )

yyy           IN    A    000.\|something000.000.001
something-\|otheryyy IN    A    000.000.000.001
other-\|\)${ARG}[[:space:]]\+IN[[:space:]]\+A/d"yyy /etc/nsd/zones/domain    IN    A    000.com000.zone000.001
else.yyy      IN    A    000.000.000.001

butI would like it wont work (works if copy paste this and runto be in command line but not froma bash script) also tried escaping the dot, not working.. so I can call e. Please assistg.

Edit:

delete_domain.sh xxx

There is one additional caveat - perhaps this is why it looks complicated - this script is called via the C++ script that makes it executable by non-root users. I am not sure what type of notation is [[:space]] but I suppose it was required due to the script being called by external c++ script and not directlyThanks.

I have a code like this to parse zone file and remove whatever its told to remove:

#!/bin/bash

for ARG in "$@"
do
    sed -i "/^\(something-\|other-\|\)${ARG}[[:space:]]\+IN[[:space:]]\+A/d" /etc/nsd/zones/domain.com.zone
done

And it works great for removing lines like

xxx           IN    A    000.000.000.000
something-xxx IN    A    000.000.000.000
other-xxx     IN    A    000.000.000.000

Now I get a subdomain that I need to remove say else.xxx so entry is like:

else.xxx      IN    A    000.000.000.000

I tried modifying the script like this

sed -i "/^\(else.\|something-\|other-\|\)${ARG}[[:space:]]\+IN[[:space:]]\+A/d" /etc/nsd/zones/domain.com.zone

but it wont work (works if copy paste this and run in command line but not from bash script) also tried escaping the dot, not working... Please assist.

Edit:

There is one additional caveat - perhaps this is why it looks complicated - this script is called via the C++ script that makes it executable by non-root users. I am not sure what type of notation is [[:space]] but I suppose it was required due to the script being called by external c++ script and not directly.

I have a input file that contains DNS zone entries

; whatever.foo [000000]
$ORIGIN whatever.foo.
$TTL 8400
@       IN      SOA     ns1.whatever.foo.      admin.whatever.foo. (
2017101913 ; serial number
                    21600                    ; refresh
                    8400                     ; retry
                    1209600                 ; expire
                    8400                    ; ttl
                    )

xxx           IN    A    000.000.000.000
something-xxx IN    A    000.000.000.000
other-xxx     IN    A    000.000.000.000
else.xxx      IN    A    000.000.000.000

yyy           IN    A    000.000.000.001
something-yyy IN    A    000.000.000.001
other-yyy     IN    A    000.000.000.001
else.yyy      IN    A    000.000.000.001

How do I remove for example entries that belong to xxx subdomain domain?

Output should be

; whatever.foo [000000]
$ORIGIN whatever.foo.
$TTL 8400
@       IN      SOA     ns1.whatever.foo.      admin.whatever.foo. (
2017101913 ; serial number
                    21600                    ; refresh
                    8400                     ; retry
                    1209600                 ; expire
                    8400                    ; ttl
                    )

yyy           IN    A    000.000.000.001
something-yyy IN    A    000.000.000.001
other-yyy     IN    A    000.000.000.001
else.yyy      IN    A    000.000.000.001

I would like it to be in a bash script so I can call e.g.

delete_domain.sh xxx

Thanks.

added 1 character in body
Source Link

I have a code like this to parse zone file and remove whatever its told to remove:

#!/bin/bash

for ARG in "$@"
do
    sed -i "/^\(something-\|other-\|\)${ARG}[[:space:]]\+IN[[:space:]]\+A/d" /etc/nsd/zones/domain.com.zone
done

And it works great for removing lines like

xxx           IN    A    000.000.000.000
something-xxx IN    A    000.000.000.000
other-xxx     IN    A    000.000.000.000

Now I get a subdomain that I need to remove say else.xxx so entry is like:

else.xxx      IN    A    000.000.000.000

I tried modifying the script like this

sed -i "/^\(else.\|something-\|other-\|\)${ARG}[[:space:]]\+IN[[:space:]]\+A/d" /etc/nsd/zones/domain.com.zone

but it wont work (works if copy paste this and run in command line but not from bash script) also tried escaping the dot, not working... Please assist.

Edit:

There is one additional caveat - perhaps this is why it looklooks complicated - this script is called via the C++ script that makes it executable by non-root users. I am not sure what type of notation is [[:space]] but I suppose it was required due to the script being called by external c++ script and not directly.

I have a code like this to parse zone file and remove whatever its told to remove:

#!/bin/bash

for ARG in "$@"
do
    sed -i "/^\(something-\|other-\|\)${ARG}[[:space:]]\+IN[[:space:]]\+A/d" /etc/nsd/zones/domain.com.zone
done

And it works great for removing lines like

xxx           IN    A    000.000.000.000
something-xxx IN    A    000.000.000.000
other-xxx     IN    A    000.000.000.000

Now I get a subdomain that I need to remove say else.xxx so entry is like:

else.xxx      IN    A    000.000.000.000

I tried modifying the script like this

sed -i "/^\(else.\|something-\|other-\|\)${ARG}[[:space:]]\+IN[[:space:]]\+A/d" /etc/nsd/zones/domain.com.zone

but it wont work (works if copy paste this and run in command line but not from bash script) also tried escaping the dot, not working... Please assist.

Edit:

There is one additional caveat - perhaps this is why it look complicated - this script is called via the C++ script that makes it executable by non-root users. I am not sure what type of notation is [[:space]] but I suppose it was required due to the script being called by external c++ script and not directly.

I have a code like this to parse zone file and remove whatever its told to remove:

#!/bin/bash

for ARG in "$@"
do
    sed -i "/^\(something-\|other-\|\)${ARG}[[:space:]]\+IN[[:space:]]\+A/d" /etc/nsd/zones/domain.com.zone
done

And it works great for removing lines like

xxx           IN    A    000.000.000.000
something-xxx IN    A    000.000.000.000
other-xxx     IN    A    000.000.000.000

Now I get a subdomain that I need to remove say else.xxx so entry is like:

else.xxx      IN    A    000.000.000.000

I tried modifying the script like this

sed -i "/^\(else.\|something-\|other-\|\)${ARG}[[:space:]]\+IN[[:space:]]\+A/d" /etc/nsd/zones/domain.com.zone

but it wont work (works if copy paste this and run in command line but not from bash script) also tried escaping the dot, not working... Please assist.

Edit:

There is one additional caveat - perhaps this is why it looks complicated - this script is called via the C++ script that makes it executable by non-root users. I am not sure what type of notation is [[:space]] but I suppose it was required due to the script being called by external c++ script and not directly.

added 328 characters in body
Source Link
Loading
Source Link
Loading