Regex 从c文件中提取头文件名的正则表达式
如何像这样从包含标题的c文件中提取标题Regex 从c文件中提取头文件名的正则表达式,regex,bash,sed,grep,Regex,Bash,Sed,Grep,如何像这样从包含标题的c文件中提取标题 #include <tema4header9.h> #include <tema4header3.h> #include <stdio.h> #include <longnametest/newheader.h> #include <net/header.h> #include "last-test-Zhy3/DrRuheader.h" #include <last
#include <tema4header9.h>
#include <tema4header3.h>
#include <stdio.h>
#include <longnametest/newheader.h>
#include <net/header.h>
#include "last-test-Zhy3/DrRuheader.h"
#include <last-test-8fF7/a5xyheader.h>
这应该起作用:
sed -nr 's/#include\s+[<"]([^>"]+)[>"].*/\1/p'
sed-nr的/#包括\s+[“]./\1/p”
这应该可以:
sed -nr 's/#include\s+[<"]([^>"]+)[>"].*/\1/p'
sed-nr的/#包括\s+[“]./\1/p”
grep
解决方案:这是使用perl正则表达式并打印之间的任何内容“grep
解决方案:这是使用perl正则表达式并打印之间的任何内容”尝试:
awk'{match($0,/[Try:
awk'{match($0,/[您的预期输出是什么?tema4header9.h
,等等?您的预期输出是什么?tema4header9.h
,等等?只是”(?)对于代码> > GRP @ NIN是非常必要的,而不是从C++代码文件中的非期望行中提取一些数据。C< <代码> >代码> >我想让部分在引号和代码>中提取。有人能告诉我如何编写上面的GRIP类似的正则表达式吗?对于代码> > GRP @ NIN是非常必要的,而不是从代码中的不希望的行中提取一些数据。C<代码>代码> >我想让部分在引号和代码中提取。有人能告诉我如何编写C++的ReXEX搜索的GRIP类正则表达式吗?
grep -oP '^#include.*(<|")\K.*(?=>|")' headers
tema4header9.h
tema4header3.h
stdio.h
longnametest/newheader.h
net/header.h
last-test-Zhy3/DrRuheader.h
last-test-8fF7/a5xyheader.h
awk '/#include/{gsub(/<|>|"/,"",$2);print $2}' headers
tema4header9.h
tema4header3.h
stdio.h
longnametest/newheader.h
net/header.h
last-test-Zhy3/DrRuheader.h
last-test-8fF7/a5xyheader.h
awk '{match($0,/[<"].*[>"]/);print substr($0,RSTART+1,RLENGTH-2)}' Input_file