Applescript-对于 grep 找到的每个项目
这段代码显然行不通,但我正在寻找语法更改以使其工作。
for every item that grep finds
set myCommand to do shell script "grep -w word test.log"
set mySecondCommand to do shell script "grep -w end test.log"
end
以下输出应该是正确的(我想要的):
word
end
word
end
相反,我得到的是因为我没有这个理论上的“对于 grep 找到的每个项目”语句(我不想要这个输出):
word
word
end
end
This code obviously won't work but I'm looking for a syntax change to make it work.
for every item that grep finds
set myCommand to do shell script "grep -w word test.log"
set mySecondCommand to do shell script "grep -w end test.log"
end
The following output should be correct (What I want):
word
end
word
end
instead I get because I do not have this theoretical "for every item that grep finds" statement (I don't want this output):
word
word
end
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的初始 grep 结果将采用字符串格式,例如。一根长绳子。为了迭代它们,您需要将字符串转换为列表,因此我使用“paragraphs”命令。一旦获得列表格式的初始 grep 结果,就可以使用重复循环来处理列表中的项目。当您处理这些项目时,您需要将这些结果存储在一个新列表中,以便在脚本结束时您可以查看总计结果。像这样的东西...
Your initial grep results will be in string format eg. one long string. In order to iterate them you will need to turn the string into a list, thus I use the "paragraphs" command. Once you have the initial grep results in list format, then you can use a repeat loop to process the items in the list. When you process the items you will need to store those results in a new list so that at the end of the script you can view the results in total. Something like this...