テキストファイルでいっぱいのフォルダ内のテキストを置き換える必要があります。どうすればいいですか?
ありがとう!
tell application "Finder"
set l to files of desktop as alias list
end tell
repeat with f in l
set input to read f as «class utf8»
set text item delimiters to "search"
set ti to text items of input
set text item delimiters to "replace"
set b to open for access f with write permission
set eof b to 0
write (ti as text) to b as «class utf8»
close access b
end repeat
私は主に次のようなTextMateまたはRubyスクリプトのプロジェクトでfindを使用します。
Dir["#{ENV['HOME']}/Desktop/*"].each do |f|
input = File.read(f).gsub(/search/, "replace")
File.open(f, "w") { |f| f.print(input) }
end
sedを使用することもできます。
sed -i '' 's/search/replace/g' ~/Desktop/*