2017-05-24 5 views
0

Applescript、psqlを使用してdbにアクセスし、xmlファイルをローカルに書き込みました。しかし、このXMLファイルには、 "\ n"という改行文字が含まれているため、意図したとおりにXMLデータを使用するのに問題があります。 TextEditでの簡単な検索/置換が可能です.Applescriptでこれからやりたいことがあります。私は今、この試みているApplescriptを使用してxmlファイルの " n"を検索して削除する

<row xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\n <reduction>95.79</reduction>\n <name>360mm</name>\n <name>ABC</name>\n <description>test with eyemark</description>\n <one_up_repeat>180</one_up_repeat>\n <one_up_across>650</one_up_across>\n <foil_width>650</foil_width>\n</row>\n\n 

: 一般的なXMLデータがすべて "\ nを" とこのようになります

do shell script "/bin/cat /Users/alex/016136.xml | /usr/bin/sed 's/\\n/ /' > 016136.xml" 

をしかし

sh: 016136.xml: Permission denied 

を取得するより良い方法はありますシェルsedを使用して、xmlファイル内のすべての "\ n"を検索して削除しますか?ありがとう、アレックス

+0

私はapplescriptの構文についてはわかりませんが、問題が何であるかはわかりませんが、 'cat' ...'/usr/bin/sed 'を使う必要はありません/ \\ n// '/ Users/alex/016136.xml'が行います...あなたのタイトルは削除を意味します。その場合は ''/\\ n //' ' – Sundeep

+0

である必要があります。変更を同じファイルに書き戻すには、 '-i'オプションを使うべきです(https://stackoverflow.com/documentation/sed/3640/in-place-editing/12529/portable-use#t=を参照してください)。 201705240653187241344)... '016136.xml'と'/Users/alex/016136.xml'が同じファイルを意味する場合、空のファイル – Sundeep

+0

@Sundeepがあります。私は今これを使っています: do shell script "/ usr/bin/sed -i.original '/ \\ n // g' /Users/alex/016136.xml" しかし、 '\ n'は削除され、ファイルはエラーメッセージなしで変更されません。何か案が?ありがとう、アレックス – Alex

答えて

0

ありがとうございます!これはうまくいきます:

set myFiles to (choose file with multiple selections allowed) 
repeat with aFile in myFiles 
    set myData to do shell script "cat " & quoted form of (aFile's POSIX path) 
    set newData to do shell script "echo " & quoted form of myData & " | sed 's/\\n//g' > " & quoted form of (aFile's POSIX path) 
end repeat 
関連する問題