Find in files – translations texts

Use case

Follow this article if you want to locate multiple occurrences of a string in a folder using a regular expression pattern.

 Find all occurrence of pattern

Using the following code in the Linux command line you will copy all occurrence of the given pattern in a temporary file

 find ./ -name '*.*' -exec grep -o -E "language->get(.*?)" {} > output.txt  \;

OR you can use this 

find ./ -name '*.*' -exec grep -o -E -Hn "language->get(.*?)" {} > output.txt2  \;

Process found parts

Using a simple text editor compatible with the regular expression you will be able to process the temporary file to the wanted format.

See the attached screenshot.


In my case I had to find all $this->get(‘Any text here’) in my PHP files and create a translation file for the Opencart platform in the following format:

$_['Any text here'] = 'Any text here';
$_['Any text here'] = 'Any text here';