Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract a list of screaming snake case strings out of multiple files?

I am searching for a way to extract "screaming snake case" strings from multiple files.

Screaming snake case is upper case words separated by underscore. A regular expression would be ([A-Z]*_?[A-Z]*)*.

Now I am searching for a way to find such matching strings in multiple files. I expect grep or find could help?

What I have:

  • multiple files in multiple sub directories
  • shell possibilities of cygwin (so most common Linux commands are available)
  • It could happen that multiple such strings are in one line

For example:

Some text WITH some SNAKE_CASE words.

The output should be a list like:

WITH
SNAKE_CASE

The use case for this is, that the snake case words are used as i18n keys for maintaining a properties file but there is no IDE support to keep all of them in sync.

What I am now using is:

find . -name "*.js" -exec grep -oP '\b[A-Z]+(_[A-Z]+)*\b' {} + | cut -d':' -f2 | sort | uniq

Thanks for support

like image 445
user3783327 Avatar asked Jul 16 '15 09:07

user3783327


1 Answers

Think you mean this,

grep -oP '\b[A-Z]+(_[A-Z]+)*\b' file

Just pass the above regex to find command.

find FOLDER -type f -exec grep -oP '\b[A-Z]+(_[A-Z]+)*\b' {} +
like image 99
Avinash Raj Avatar answered Nov 13 '22 07:11

Avinash Raj