我已经使用Applescript,psql成功访问了数据库并在本地编写了一个xml文件。然而,这个xml文件包含断路器" \ n"全部因此我无法按预期使用xml数据。 TextEdit中的一个简单的查找/替换工作 - 我现在想在Applescript中做。 对于所有" \ n":
,典型的xml数据看起来像这样<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
我现在试过这个:
do shell script "/bin/cat /Users/alex/016136.xml | /usr/bin/sed 's/\\n/ /' > 016136.xml"
但是
sh: 016136.xml: Permission denied
有没有比shell sed更好的方法来查找和删除所有&#34; \ n&#34;在xml文件中?谢谢Alex,
答案 0 :(得分: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