Regular Expression Matching NOT

[problem]

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

[/problem]

[solution]

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

[/solution]

[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).

[/example]

[reference]

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

[/reference]

If you have found my website useful, please consider buying me a coffee below 😉

Leave a Reply

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