If you open Terminal, cd into the directory that contains these files, I find this to be the best to find those files:
find . -type f -name "*.m*" -print
This finds everything within the current
. directory that is a file
-type f that has a name of
*.m,
*.mm,
*.mmmmm, and so on (the
*.m*). You then output each resulting file
-print to the console (or a pipe). If you wish to pass each of the files to another process (using
xargs), it is best to replace
-print with
-print0 so it correctly handles whitespace in the filenames.
Next, use sed to replace the text within those results. (The version of sed that comes with Mac is different from the GNU sed, and will not properly handle newlines and other special characters correctly. You may need to grab that version if this does not work for you.)
The basic structure of the replacement is:
sed -i "" -e 's/NSLocalizedString(\(.*\), \(.*\))/NSLocalizedStringFromTable(\1, table, \2)/g' "FILENAME"
The
-i "" replaces the file in-place (saves it to the same file that was opened).
-e just means the next text is going to be an expression. Starting the expression with
s/ signifies that you are going to be doing a search-and-replace. It is usually in the format:
s/[search for this pattern]/[replace with this pattern]/g
The
/g at the end means 'global', or "do this for as many instances that are found on each line as possible."
The search pattern, /NSLocalizedString(\(.*\), \(.*\))/, finds that text and then copies the contents of the \(...\) tags (you have to escape the parentheses so sed knows to remember it).
The replacement pattern, /NSLocalizedStringFromTable(\1, table, \2)/, replaced the NSLocalizedString with NSLocalizedStringFromTable, and then tucked the exact replacement of the first and second \(.*\) pairs into the \1 and \2 references.
If you had this literal value:
NSLocalizedString(@"Darn tootin'", @"How they say 'that is correct' in some dialects");
then the result would become:
NSLocalizedStringFromTable(@"Darn tootin'", table, @"How they say 'that is correct' in some dialects");
Now, @shellter asked in the comments whether you meant that you want the literal word table to be in there, whether parameter 1 or parameter 2 should come from different tables, etc. That would certainly change the format of this search string.
Lastly, you can combine the two above features into one long shell script and run it in Terminal:
find . -type f -name "*.m*" -print0| \
xargs -0 -I FILENAME \
sed -i "" -e 's/NSLocalizedString(\(.*\), \(.*\))/NSLocalizedStringFromTable(\1, table, \2)/g' "FILENAME"
If you meant for different values to be in place of "var1" and "var2" that you mentioned in your original post, you'll need to specify.
grep,sedandfindwill solve this problem. Hint: It is a "simple search and replace" problem.