Unicode -> sed -> Unicode

Hi all,

I’m using sed to process file contents for a number of replacement

set res to do shell script	"tr '\\r' ' \\n' < " & myFile & " | sed -E 's/(c*pr).*/\\1 " & w & "/' > " & myFileNew

Input file myFile has unicode coding but output one myFileNew (after processing by sed) is Mac OS Roman
However I need coding remains intact.

How to maintain Unicode after processing with sed?

Here’s a subroutine for writing to a file. So get your shell results and use this to write the file. You can set the “mode” to unicode text. I think that may solve your problem.

on writeTo(this_data, target_file, append_data, mode) -- append_data is true or false, mode is string, unicode text etc. (no quotes around either)
	try
		set target_file to target_file as Unicode text
		if target_file does not contain ":" then set target_file to POSIX file target_file as Unicode text
		set the open_target_file to open for access file target_file with write permission
		if append_data is false then set eof of the open_target_file to 0
		write this_data to the open_target_file starting at eof as mode
		close access the open_target_file
		return true
	on error
		try
			close access file target_file
		end try
		return false
	end try
end writeTo