编辑大量文本文件
我有大约 350 个文本文件,其中包含硬盘上 5 个文件夹的全部内容。对于每个文件,我想删除每个文件开头和结尾处指定数量的字符。我对 AppleScript 不了解,但怀疑它可能适合我想要实现的目标。任何有关自动化此操作的帮助将不胜感激,因为手动编辑这些文件是一项艰巨的任务。非常感谢。
需要从每个文件的开头删除以下文本:
STARTTYPE:RGIN
MODEXP:NO
需要从每个文件的末尾删除以下文本:
REFACTORSCALE:2.0
ENDTYPE:FACTORED
I have about 350 text files which comprise the entire contents of 5 folders on my HD. For each of these files, I would like to delete a specified number of characters at the start and end of each file. I have no knowledge of AppleScript but suspect it may be suitable for what I want to achieve. Any help on automating this would be greatly appreciated as manually editing these files is a daunting task. Thank you very much.
The following text needs to be removed from the start of each file:
STARTTYPE:RGIN
MODEXP:NO
The following needs to be removed from the end of each file:
REFACTORSCALE:2.0
ENDTYPE:FACTORED
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
OS X 是否有 unix 命令 sed ?它正是为了解决此类问题而设计的。
您可能会说(假设每个文件中要删除的文本都相同):
例如,假设一堆 .txt 文件需要在您的主目录下的这 5 个目录中完成这些编辑。你可以这样做:
Does OS X have the unix command sed? It was designed to solve precisely this type of problem.
You would say (assuming your text to remove is the same in every file):
For example, lets say a bunch of .txt files need to have these edits done in these 5 directories under your home directory. You could do: