mirror of
https://github.com/jbowdre/runtimeterror.git
synced 2024-12-27 05:02:18 +00:00
2.3 KiB
2.3 KiB
title | date | description | featured | draft | toc | usePageBundles | codeLineNumbers | series | tags | comment | |||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Cat a File Without Comments | 2023-02-22 | A quick trick to strip out the comments when viewing the contents of a file. | false | false | true | true | false | Tips |
|
true |
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 # [tl! .cmd]
For added usefulness, I alias this command to ccat
(which my brain interprets as "commentless cat") in my ~/.zshrc
:
alias ccat='egrep -v "^\s*(#|$)"'
Now instead of viewing all 75 lines of a mostly-default Vagrantfile, I just see the 7 that matter:
wc -l Vagrantfile # [tl! .cmd]
75 Vagrantfile # [tl! .nocopy]
ccat Vagrantfile # [tl! .cmd]
Vagrant.configure("2") do |config| # [tl! .nocopy:start]
config.vm.box = "oopsme/windows11-22h2"
config.vm.provider :libvirt do |libvirt|
libvirt.cpus = 4
libvirt.memory = 4096
end
end # [tl! .nocopy:end]
ccat Vagrantfile | wc -l # [tl! .cmd]
7 # [tl! .nocopy]
Nice!