Regular Expression Matching NOT

Problem

You want to find a line, not matching the pattern.



Solution

I find this invaluable whilst editing crons. Or in vi – like this: [^x] where x equals the character you want to ignore.



Example


For example after performing a crontab -e, wanting to skip comments.


crontab -e
/^[^#]

Also with sed – substituting tags, etc:


sed 's#]*>##g' filename

This says edit your crontab, match the next line that has a beginning, immediately followed by a character that is not a comment.

After performing this once, just type n – for the next match (i.e. next line that does not start with a comment).



Reference

[tags]UNIX, vi, regular expression, Unix Coding School[/tags]



Leave a Reply

Your email address will not be published. Required fields are marked *