0

I found a command to find documents in my all-level folders and directories that are utf-8 with BOM and then remove the BOM. But it doesn't seem to work on my computer(osx)...Should I install moodle on my machine first in order to run it in my command line?

Below is the command:

find . -type f -exec sed 's/^\xEF\xBB\xBF//' -i.bak {} \; -exec rm {}.bak \;

The result I got is sed: -i.bak: No such file or directory and all the content in the files, which seems very weird.

Thank you for your help!

Alastair McCormack
  • 26,573
  • 8
  • 77
  • 100
Penny
  • 1,218
  • 1
  • 13
  • 32

1 Answers1

2

The command you found was for GNU's sed, which supports optional arguments anywhere. Worst of all, OS X's sed doesn't seem to support non-ASCII byte sequences.

Instead, for OS X use the following answer, which uses Perl: https://stackoverflow.com/a/9101056/1554386

Tying it into find is as follows:

find . -type f -exec perl -e 's/\xef\xbb\xbf//;' -pi.bak {} \;

You can add the -exec rm {}.bak \; from your command if you wish, but you can just as easily do that separately

Community
  • 1
  • 1
Alastair McCormack
  • 26,573
  • 8
  • 77
  • 100
  • Thank you Alastair. That helps a lot! I'll use it in the future! :) – Penny Dec 11 '15 at 22:05
  • Np. BTW, make sure you upvote and accept questions if they work for you. People are more likely to respond if they think you'll reward them for answering. – Alastair McCormack Dec 11 '15 at 22:08
  • Oops, I thought I already voted you up. So just voted. Thank you again! – Penny Dec 11 '15 at 22:41
  • No worries - also see this about accepting answers: http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work . Basically, you get extra reputation for accepting – Alastair McCormack Dec 11 '15 at 22:42