0

I’m using bash shell with Mac El Capitan. How can I scan for part of an 8-byte character in a series of files? I got an error when building a project that read

Incorrect string value: '\xF3\x95\x90\x8D\xEA\x93...' for column 'CODE' at row 1

and I’d like to figure out where this string value is coming into play. Unfortunately the error does not give me more information but I know the directory of all the potential files where this could live.

1 Answers1

0

I have corrupted one of my shell files on purpose in the current directory, inserting a 0xf3 char using an hex editor.

I've written this (clumsy) script which uses od (octal dump) in hex mode char-by-char, with hex offset, and greps for the infamous f3 char in the current directory and in all directories below, filtering on files and name (so you can remove the name filtering it still works)

find . -type f -name "*.sh" | while read f
do
    line=$(od -Ax -t x1 $f | grep -w f3)
    if [ $? = 0 ] ; then
      echo file $f is corrupt: $line
    fi
done

result on my directory:

file ./quote.sh is corrupt: 000010 69 6d 61 6c f3 3d 24 28 6d 79 73 71 6c 20 2d 75
Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
  • I don't know what file this character occurs in within my directory so I switched your line "for f in *.sh" to "for f in *" but get the error "od: src: read error: Is a directory" and "od: target: read error: Is a directory". –  Sep 19 '16 at 14:00