Cat a File Without Comments

It's super handy when a Linux config file is loaded with comments to tell you precisely how to configure the thing, but all those comments can really get in the way when you're trying to review the current configuration.

Next time, instead of scrolling through page after page of lengthy embedded explanations, just use:

1egrep -v "^\s*(#|$)" $filename

For added usefulness, I alias this command to ccat (which my brain interprets as "commentless cat") in my ~/.zshrc:

1alias ccat='egrep -v "^\s*(#|$)"'

Now instead of viewing all 75 lines of a mostly-default Vagrantfile, I just see the 7 that matter:

 1; wc -l Vagrantfile
 275 Vagrantfile
 3
 4; ccat Vagrantfile
 5Vagrant.configure("2") do |config|
 6  config.vm.box = "oopsme/windows11-22h2"
 7  config.vm.provider :libvirt do |libvirt|
 8    libvirt.cpus = 4
 9    libvirt.memory = 4096
10  end
11end
12
13; ccat Vagrantfile | wc -l
147

Nice!


runtimeterror


 jbowdre