awk 笔记之二 正则表达式

来源:互联网 发布:淘宝里的企业店铺好吗 编辑:程序博客网 时间:2024/05/16 11:57

1. 正则表达式的使用方法

     a)   / regexp /  在整行中匹配

     b)  exp ~ /regexp/    在exp中匹配   如: awk ' $1 ~ /J/' aaa.txt

     c)  exp !~ /regexp/    在exp没有匹配到


  2.  Escape Sequence

     \\

     \a

     \b

     \f

    \n

     \r

    \t

    \v

    \nnn

   \xhh

   \"

   \/

3. 正则表达式操作符

   \ , ^, $, ., [...], [^...],|, (...), *, +, ?, {n}, {n,}, {n,m},

4. 字符列表

    [a-dx-z]

    字符类(Character class)

   [:alnum:] Alphanumeric characters.
   [:alpha:] Alphabetic characters.
   [:blank:] Space and TAB characters.
   [:cntrl:] Control characters.
   [:digit:] Numeric characters.
   [:graph:] Characters that are both printable and visible. (A space is printable but not visible, whereas an ‘a’ is both.)
   [:lower:] Lowercase alphabetic characters.
   [:print:] Printable characters (characters that are not control characters).
   [:punct:] Punctuation characters (characters that are not letters, digits, control characters, or space characters).
   [:space:] Space characters (such as space, TAB, and formfeed, to name a few).
   [:upper:] Uppercase alphabetic characters.
   [:xdigit:] Characters that are hexadecimal digits.


5. tolower() , toupper()

    

原创粉丝点击