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

发布于 2025-01-05 23:43:46 字数 655 浏览 5 评论 0原文

我有一个如下所示的文件,它是从我用 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 程序中还是必须单独运行?

I have a file that looks like the following, which is outputted from a program i wrote in 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? If not what programs should i look at considering i am woking on OSX? sed, gawk, perl, python? Can i insert these programs in my applescript program or will i have to run separately?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

美人如玉 2025-01-12 23:43:46

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

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

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
花间憩 2025-01-12 23:43:46

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

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

Here is a good tutorial:
http://www.grymoire.com/Unix/Sed.html

set xxx to "Here is my input" 
do shell script "echo " & xxx & " | sed 's/my/your/'"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文