I am attempting to perform a find and replace of underscores to dots in a directory for certain filetypes only (.mkv, .mp4, .avi). This is the code that I am using (I'm on Mac OS X 10.9):find . \( -name '*.mp4' -o -name '*.mkv' -o -name '*.avi' \) -print0 |     xargs -0 sed -i '' -e 's/\./_/g'I read up on two solutions, both which have not worked.I first I added the following to my ~/.bash_profile:export LC_CTYPE=C export LANG=CThis caused the same error, so then I tried using:LC_ALL=C sed ... and this did not work, I received this error:xargs: LC_ALL=C: No such file or directoryAny other suggestions? I'm quite new to shell.EDIT: This is what I am trying to accomplish:I am trying to go through a directory and replace the underscores in the file names to dots.Example:random_movie.mp4 should be random.movie.mp4
find and sed (find and replace) causes illegal byte sequence on Mac OS X
shell;osx
You should be using -exec here:find . \( -name '*.mp4' -o -name '*.mkv' -o -name '*.avi' \) \    -exec sh -cf 'IFS=._    for f do d=${f%/*} f=${f##*/}    [ -n ${f##*_*} ] && continue    set -- $f     printf %s\n mv \\ $d/$f \\ $d/$*    done' find.rename.shc {} +As written this only prints the command it will execute if you go through with it. For example, running the above on my .../media/Videos directory prints some of the following:mv \/mnt/bcache/media/Videos/TV/Adventure_Time/Adventure_Time.s05e37.The_Box_Prince.mp4 \/mnt/bcache/media/Videos/TV/Adventure_Time/Adventure.Time.s05e37.The.Box.Prince.mp4mv \/mnt/bcache/media/Videos/TV/Adventure_Time/Adventure_Time.s05e38.Red_Starved.mp4 \/mnt/bcache/media/Videos/TV/Adventure_Time/Adventure.Time.s05e38.Red.Starved.mp4In order to go through with it you'd need to change:...set -- $fprintf %s\n mv \\ $d/$f \\ $d/$*......to just......set -- $f; mv $d/$f $d/$*...In general you should avoid passing filenames and similar over a pipe because when you do so you lose the the delimiters to the head and tail of the filename - it ceases to be an argument and becomes instead a sequence of bytes in a stream. The -exec option to find enables you to retain those delimiters in a child process of the running find process. With + it acts like xargs - execing the specified child process only as often as necessary to avoid an ARGMAX condition.Regarding the sed problem - you might try:LC_ALL=C xargs sed ...That should at least avoid xargs interpreting the environment variable declaration as an argument. It will not help you to edit any filenames, though.A last note - the issue you mention is generally caused by an incomplete multi-byte sequence occurring in pattern space. POSIX specifies that . cannot match part of a character - and so .* loses its meaning in that context. Forcing the C locale should resolve it - but another option for clearing hold/pattern spaces with a GNU sed is the z command.