简体   繁体   中英

Why the command used to remove BOM doesn't work?

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM