[Help Wanted] Filtering comments out of hostfiles in Linux
See original GitHub issueHi,
I’m using a hostfile from this project on my local dns server to block ads. However I have some problems in my script with inline comments:
# copy dns to all_domains (tempfile)
cat StevenBlack-hosts | grep '^0.0.0.0' | egrep -v '^$|#|127.0.0.1|255.255.255.255|::1' | cut -d " " -f 2 >> $all_domains
# include local blacklist and hostfiles from other sources
cat $manuell_blacklist >> $all_domains
# remove comments and empty lines
cat $all_domains | egrep -v '^$|#' | sort | uniq > $all_domains_uniq
# dns entries should be resolved with zone containing 0.0.0.0
cat $all_domains_uniq | sed -r 's/(.*)/zone "\1" {type master; file "\/etc\/bind\/db.blocked";};/' > $zonefile
This will remove entries like
foo.bar # This may interefere with example.com
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
How to ignore comments at the end of the each line?
I am reading the host file by ignoring the comments and write it to the other file. I am reading with regular expression...
Read more >Solved: comments in /etc/hosts and /etc/named.data
Solved: I'd like to add comments to /etc/hosts such as: 209.90.236.66 wally mail # comment 209.90.236.67 frank # comment Is there any problem...
Read more >cli utility/cronscript to automate hostsfile adblocking
Filters out redundant entries, excessive white spaces, and comments to minimize resultant file size. Can use links to zipped files (using ...
Read more >How to Modify and Manage the Hosts File on Linux
Want to block certain websites and limit internet access on Linux? Here's what you need to know about the hosts file.
Read more >personalized block list via host file · Issue #989
gorhill commented on Nov 29, 2015. Blocking popup windows work only when the popup filter option is present. Automatically applying the popup ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hey @mueller-ma this is great!
https://github.com/StevenBlack/hosts/wiki/Bind-DNS-Server https://github.com/mueller-ma/block-ads-via-dns