How to ignore the lines starts with # using grep / awk

awk -F: '/^[^#]/ { print $2 }' /etc/oratab | uniq

/^[^#]/ matches every line the first character of which is not a #; [^ means "none of the charaters before the next (or rather: closing) ].

As only the part between the first two colons is needed -F:' makesawksplit the line at colons, andprint $2` prints the second part.


Using grep:
grep -vE "^#" or grep -E "^[^#]"


The next awk statement will skip the current line, that is useful if you have to match multiple blocks in your script.

awk '
/^#/ {next}
/ pattern 1 / {    }
/ pattern 2 / {    } '  filename