取C语言头文件的文件名

main.c内容如下
 1 #include <str1.h>
 2 #include "str2.h"
 3 #include<str3.h>
 4 #include"str4.h"
 5 #include        <str5.h>
 6 #include        "str6.h"
 7     #include <str7.h>
 8     #include "str8.h"
 9 #include < str9.h >
10 #include " str10.h "

shell下执行cat main.c | sed -nre 's/^[[:space:]]*\#include[[:space:]][<\"]([^>\"./]+).*$$/\1/p'后

结果:

1 str1
2 str2
3 str7
4 str8
5  str9
6  str10

 

s/    ^[[:space:]]*\#include[[:space:]][<\"]([^>\"./]+).*$$   /    \1    /p
 ^[[:space:]]    *\#include[[:space:]]    [<\"]    (    [^>\"./]+    ).*$$    

 

正则表达式

简单测试方法:

1 打开一个终端,输入grep ‘正则表达式’

2 输入对应表达式就会出现与上述‘正则表达式’匹配的结果。

 

eg1:匹配一个单词hello,

grep '\bhello\b'

hello,;hello , hello  等都是匹配的,而helloWorld等是不匹配的,\b是匹配一个单词的开始或结束。

eg2:匹配一个单词,g*gle其中*的位置可以是1个或3个0

grep '\bgo\{1,3\}gle\b'

{x}表示前一个字符可以重复x次,{x,y}表示前一个字符可以重复x-y次(注意shell下‘{’的转义)

eg3:匹配以cn开头的字符串

grep '^cn'

一个不错的参考

posted @ 2015-02-02 16:50  cntsw  阅读(448)  评论(0编辑  收藏  举报