Previous

Next


10. Metacharacters - The Character Class

  • Be careful with character classes, especially when using negated classes!
  • Consider this example: We want to use a regex to find words in a file that don't have the letter "u" after a "q". The file that we are searching (example01.txt) looks like this:
      This is a pointless little file.
      It is full of words with the letter "q" in them.
      Some words, like qintar, do not have a u after the q.
      Other words, like quartet, do have the letter u after the q!
      There are some other words, like Qantas, that need to be looked at,
      and some other special words, like Iraqi, and last but not least,
      the word Iraq
            
  • So, we fire up grep with this command:
      grep 'q[^u]' example01.txt
            
  • What do we expect to get back?

Previous

Next

Andrew Hill

For LinuxSA Meeting, 21 November 2000