I need to extract all included libraries in a C file, but I got some problems. My solution for this is so:
grep -oP '#(?:\/\*\w*\*\/|)include(?:\/\*\w*\*\/|\s*)"\w*.h"|<\w*.h>' main.c
This regex takes library when it is in comment, for example
/*#include <stdlib.h>*/
and I don't know how to make that script gives me only name of library without #include
How to fix my regex to it work right?
UPD:
main.c
#include "string.h"
#include <stdlib.h>
#include "math.h"
#include "stdint.h"
#/*comment*/include /*comment*/ <fenv.h>
//#include <iostream>
#/**/include "something.h"
/* comment */#include "float.h"
/*#include "library.h"*/
int main() {
}
What I want:
"string.h"
<stdlib.h>
"math.h"
"stdint.h"
<fenv.h>
"something.h"
"float.h"
#
, maybe? – larsks Mar 26 '17 at 14:33sed -n 's/.*\(<.*>\).*/\1 /p' main.c
? – Valentin Bajrami Mar 26 '17 at 14:34#if
blocks will be your next problem – ilkkachu Mar 26 '17 at 14:41