我有一个由一些字符串组成的file.txt,每个字符串的结构如下:
word1 word2 word3
我想写一个脚本,它允许我找到以" word1"开头的字符串。并获得" word2"的内容和" word3"分为两个变量。
答案 0 :(得分:1)
像这样的东西
set searchTerm to "foo"
set variable1 to ""
set variable2 to ""
set theText to paragraphs of (read (choose file))
repeat with aLine in theText
set theWords to words of aLine
if item 1 of theWords is searchTerm and ((count theWords) > 3) then
set variable1 to item 2 of theWords
set variable2 to item 3 of theWords
exit repeat
end if
end repeat