0

I'm having a little trouble getting the output of diff to write to file. I have a new and old version of a .strings file and I want to be able to write the diff between these two files to a .strings.diff file.

Here's where I am right now:

diff -u -a -B $PROJECT_DIR/new/Localizable.strings $PROJECT_DIR/old/Localizable.strings >> $PROJECT_DIR/diff/Localizable.strings.diff
fgrep + $PROJECT_DIR/diff/Localizable.strings.diff > $PROJECT_DIR/diff/Localizable.txt

The result of the diff command writes to Localizable.strings.diff without any issues, but Localizable.strings.diff appears to be a binary file. Is there any way to output the diff to a UTF-8 encoded file instead?

Note that I'm trying to just get the additions using fgrep in my second command. If there's an easier way to do this, please let me know.

Thanks,

Sean

seanoshea
  • 5,556
  • 3
  • 20
  • 28
  • 3
    diff doesn't create binary files. Are you sure you understand the diff output format (it seems like you do). So that takes you back to your source, Localizable.strings. It sounds like you have code that uses non-US/UK English. Have you looked at running diff with different values for the LC_* vars and LANG? Good luck. – shellter Oct 30 '12 at 19:18

1 Answers1

1

First, you probably need to identify the encoding of the Localizable.strings files. This might be done in a manner described by How to find encoding of a file in Unix via script(s), for example.

Then probably you need to convert the Localizable.strings file to UTF-8 with a tool like iconv using commands something like:

iconv -f x -t UTF-8 $PROJECT_DIR/new/Localizable.strings >Localizable.strings.new.utf8
iconv -f x -t UTF-8 $PROJECT_DIR/old/Localizable.strings >Localizable.strings.old.utf8

Where x is the actual encoding in a form recognized by iconv. You can use iconv --list to show all the encodings it knows about.

Then, you probably need to diff without having to use -a.

diff -u -B Localizable.strings.old.utf8 Localizable.strings.new.utf8 >Localizable.strings.diff.utf8
Community
  • 1
  • 1
kbulgrien
  • 4,384
  • 2
  • 26
  • 43
  • Thanks kbulgrien & shelter. Knowing the encoding of the .strings files before executing the iconv command was exactly what I needed. – seanoshea Oct 30 '12 at 21:17