mkfl
cat src.fl | xargs grep FOO > t

Many time you’ll want some context around your search so use

cat src.fl | xargs grep -C5 FOO > t

Then if there are a lot of sub-directories you’ll want to strip all of the directory names off so that you can see more of the line that matched (before the line wraps).

cat t | sed 's,.*/\([^/]*\.[^/:]*:.*\),\1,' | less
cat t | sed 's,.*/\([^/]*\.[^/:]*:.*\),\1,' | trim | less

An explanation of the Regex is:

  • .*\/ → everything up to the last /
  • \([^/]*\.[^/:]*:.*\):
    • [^/]* → filename without /
    • \. → literal dot before extension
    • [^/:]* → extension (no / or : allowed inside)
    • :.* → colon + everything after

NOTE: If you don’t have mkfl use the following to create a list of source files. Update the

find . \( -name node_modules -o -name target -o -name build -o -name .idea -o -name .git -o -name RCS \) -prune -false -o \! -type d -print  | sort > all.fl
egrep -i '\.[ch]$|makefile$|pom.xml$|Dockerfile$|\.md$|\.gitignore$|\.gitlab-ci.yml' $TODIR/all.fl > src.fl
egrep -i '\.java$|\.cxx$|\.cpp$|\.hxx$|\.js$|\.json$|\.sql$|\.ec$|\.[k]sh$' $TODIR/all.fl >> src.fl

This is a simplified solution and isn’t perfect.


<
Previous Post
Enable macros in my ThingsToDo.docx Microsoft Word document
>
Blog Archive
Archive of all previous blog posts