[英]Format text file on OSX to tab delimited text file
I have a file that looks like the following, which is outputted from a program i wrote in applescript. 我有一个看起来像下面的文件,该文件是从我用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
I need to put into a format that will be compatible with a database. 我需要输入一种与数据库兼容的格式。 So a tab delimited format.
因此,制表符分隔格式。 This is the format i would like to output it in. I don't need all the data above just what i select
这是我想输出的格式。我不需要上面选择的所有数据
123 456 0 1 2 3 4 5 text text
123 456 0 1 2 3 4 5 text text
I am thinking regular expressions to format text as i need. 我正在考虑使用正则表达式来按需要格式化文本。 Can i do this in applescript?
我可以在applescript中执行此操作吗? If not what programs should i look at considering i am woking on OSX?
如果不是,我应该考虑哪些程序才能在OSX上正常运行? sed, gawk, perl, python?
sed,gawk,perl,python? Can i insert these programs in my applescript program or will i have to run separately?
我可以将这些程序插入applescript程序,还是必须单独运行?
When you are getting your selected items, just add the tabs as you go. 获取所选项目时,只需随需添加选项卡即可。 You can also put the items into a list, where you can use text item delimiters to convert to a string with tabs between the items.
您还可以将项目放入列表中,在这里您可以使用文本项目定界符将其转换为在项目之间带有制表符的字符串。
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
Here is a good tutorial: http://www.grymoire.com/Unix/Sed.html 这是一个很好的教程: http : //www.grymoire.com/Unix/Sed.html
set xxx to "Here is my input"
do shell script "echo " & xxx & " | sed 's/my/your/'"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.