I have this small script to visualize config files without the comment lines:
cat $1 | grep -Ev '[:blank]*#|^[:blank]*$' | pygmentize -g
but it still shows some comments in some files when they have the /* */.
How can I visualize a file, removing all comments, including /* */ ? I'm thinking in making a bash script with a line by line for, searching for the opening and closing of these comments. But I imagine that must be a better way to do this.
All the options I've seen (like this one: http://bit.ly/1BsdcDI) doesn't treat these kind of comments.
Is there an already made tool or script for this ?
Any help apreciated, thanks.
EDIT
as mentioned above, I'm targetting config files specifically. So the rules of exclusion will be:
- any line starting with '#', ';' or '//'
- any lines from the start /* to the */
- don't remove any lines that don't have /* at the start of the line (i.e. have valid codes before /*) or have */ before the end of line (i.e. have valid codes after */)
SOLUTION:
Based in the answer by @cusco and the code by @EdMorton I have created this bash script to do what I want.
#!/bin/bash
[ $# -eq 2 ] && arg="$1" || arg=""
eval file="\$$#"
sed 's/a/aA/g;s/__/aB/g;s/#/aC/g' "$file" |
gcc -P -E $arg - |
sed 's/aC/#/g;s/aB/__/g;s/aA/a/g' |
grep -Ev '^[:blank]*#|^[:blank]*$' |
grep -Ev '^[:blank]*\;|^[:blank]*$' |
pygmentize -g