💾 Archived View for gmi.runtimeterror.dev › cat-file-without-comments › index.gmi captured on 2024-07-09 at 00:03:35. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2024-05-10)

➡️ Next capture (2024-08-18)

🚧 View Differences

-=-=-=-=-=-=-

💻 [runtimeterror $]

2023-02-22

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:

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

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

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

[1] my `~/.zshrc`

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

wc -l Vagrantfile 

[2] mostly-default Vagrantfile

ccat Vagrantfile 
Vagrant.configure("2") do |config| 
  config.vm.box = "oopsme/windows11-22h2"
  config.vm.provider :libvirt do |libvirt|
    libvirt.cpus = 4
    libvirt.memory = 4096
  end
end 
ccat Vagrantfile | wc -l 
7 

Nice!

---

📧 Reply by email

Related articles

Quick Salt State to Deploy Netdata

I Ditched vSphere for Proxmox VE

Using `systemctl edit` to Delay Service Startup

---

Home

This page on the big web