Home > Blockchain >  How to search for file paths using grep
How to search for file paths using grep

Time:12-09

I am trying to get all of the file paths that are listed in a certain file and store them in an array for further use

The file paths within the files look like this:

include /app/...;

or

#include /app/...; #comment

But the the file also has other file paths so I want to find just the ones that start with include.

I tried grep 'include /[^"]*' <fileToSearch> but it is missing some files and doesn't capture them

Any help will be appreciated.

CodePudding user response:

You can try this regex:

grep 'include\s / [\w\\\-/ .]*' <fileToSearch>

Explanation: this regex match all pathes after the keyword "include" and starting by a /. The keyword and the path can be separated by any number of whitespace character.

CodePudding user response:

grep looks for any line that contains the string and return whole line.

grep "^include." or grep "^#include."

If you want to get only path (without include statement), you should use sed, awk...

  • Related