I'd like to write a shell script to optionally view files without comments (which sometimes take a lot of space so that it becomes difficult to see the lines active in a config file, etc.) and this naturally requires including a number of different commenting marks for different mimetypes. I thought I could easily find it on the Internet, but I couldn't.

I'd appreciate very much if some one can direct me to such a source (or perhaps list several most common ones properly - e.g. #TEXT for mimetypes "ABC;DEF;GHI;", <!--MULTILINETEXT--> for mimetypes "JKL;MNO", and so on).


A simpler alternative is to view the files with syntax highlighting. This allows you to more easily identify and ignore the comments.

I use highlight:

highlight() {
  command highlight -s base16/tomorrow-night -O truecolor "$1" || expand -t4 "$1"
cless() {
  highlight "$@" | less

Note, I'm colourblind, so don't abuse me for my choice of colour style.

  • Thanks for this. However, I already have a very good text editor (Kate) that features highlighting and I can even customize it to render comments almost invisible. What I need now is something a little more than that. Maybe I can find what I want in one of the source files of this utility. Then I can close this issue. ;-)
    – Sadi
    Oct 12 '20 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.