I would like to find a way to get the unique keys that are used inside .rb and .yml files. These keys are used inside the hash ENV. So, there are files that contain things like:
ENV['key']
in multiple lines and at various positions within their lines. Also, those might appear multiple times within those lines.
So, If I have the file:
blah blah blah ENV['key1'] blah blah blah ENV['key2']
blah blah blah ENV['key2']
blah blah
ENV['key3'] blah blah ENV['key2']
then I would like to get the list:
key1
key2
key3
I have managed to do this:
find . -iname "*.rb" -o -iname "*.yml" | xargs egrep 'ENV\[.(.*).\]'
but I do not know how to actually get the keys.
Any help would be much appreciated.
findis incorrect, and needs to instead befind . \( -iname "*.rb" -o -iname "*.yml" \) -exec ...– thrig Nov 27 '16 at 17:46grep -owill print each match separately. – jayhendren Nov 28 '16 at 14:33