question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Help Wanted] Filtering comments out of hostfiles in Linux

See original GitHub issue

Hi,

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:closed
  • Created 7 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found