将OSX上的文本文件格式化为制表符分隔的文本文件

时间:2012-02-15 21:42:18

标签: regex scripting applescript osx-snow-leopard tab-delimited

我有一个看起来如下的文件,它是从我在AppleScript中编写的程序输出的。

AXTitle: Blah
AXSize: Width: 300
AXSize: Height: 44
AXPosition: X: 217
AXPosition: Y: 170
AXHelp: Blah
AXValue: Value, On
AXEnabled: true
AXFocused: false
AXRole: AXStaticText
AXRoleDescription: Blah
AXTopLevelUIElement: Blah
AXWindow: Blah

我需要使用与数据库兼容的格式。因此,制表符分隔格式。这是我想输出的格式。我不需要上面的所有数据,只需要选择

123   456   0   1   2   3   4   5   text   text     
123   456   0   1   2   3   4   5   text   text  

我正在考虑正则表达式来根据需要格式化文本。 我可以用AppleScript做到这一点吗?如果不是我应该考虑哪些程序考虑我在OSX上工作? sed,gawk,perl,python?我可以在我的AppleScript程序中插入这些程序,还是必须单独运行?

2 个答案:

答案 0 :(得分:1)

当您获得所选项目时,只需添加标签即可。您还可以将项目放入列表中,您可以使用文本项分隔符转换为包含项目之间选项卡的字符串。

set X to {123, 456, 0, 1, 2, 3, 4, 5, "text", "text"}
set {tempTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, tab}
set {X, AppleScript's text item delimiters} to {X as text, tempTID}

X --> result

答案 1 :(得分:0)

这是一个很好的教程: http://www.grymoire.com/Unix/Sed.html

set xxx to "Here is my input" 
do shell script "echo " & xxx & " | sed 's/my/your/'"