检索“TODO”文本文件中的行
我正在 GEdit(文本编辑器)中编辑一个项目。当我输入 TODO 时,它会突出显示为黄色以供将来参考。我周围有很多这样的TODO
。
为了更清楚地说明我需要做什么,任何人都可以向我展示一种从一堆文件中提取任何 TODO
行并将它们放入一个名为 TODOs.txt 的文本文件中的方法。 txt ?
我有这样的东西:
// TODO:错误处理。
并希望将其放入这样的文件中:
* <文件名>; <行号>错误处理
Linux 应用程序(CLI、GUI 不介意)会更好,但正则表达式脚本或其他人可能想出的方法会很酷。
I'm editing a project in GEdit (text editor). When I type TODO
it highlights it yellow for future reference. I have quite a few of these TODO
s around the place.
To make it clearer what I need to do, can anyone show me a way to extract any TODO
lines from a bunch of files and put them into one text file called, for example, TODOs.txt
?
I have something like this:
// TODO: Error handling.
And want it to be put in a file like this:
* <file name> <line number> Error handling
A Linux application (CLI, GUI don't mind) would be preferable, but a regex script or another method someone could come up with would be cool.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
尝试 grep TODO -rnf * > TODOs.txt
try
grep TODO -rnf * > TODOs.txt
如果文件是
git
版本控制的,您可能需要重用 git 的 grep。要在源文件中 grep 查找 TODO,请在存储库的根目录中键入以下命令该命令输出如下所示:
要包含行号,请添加
-n
标志:有关更多选项,文档为 < a href="https://git-scm.com/docs/git-grep" rel="nofollow noreferrer">此处。
If the file is
git
version controlled, you might want to reuse git's grep. To grep for TODOs in your source files you type the following command at the root of the repoThe command outputs something like this:
To include the line number add the
-n
flag:For more options docs are here.
如果包含 TODO 的文件列表存储在一个名为“file_list.txt”的文件中,请运行:
这将检索包含“TODO”字符串的所有行的列表,前面加上文件名和行号,并存储TODOs.txt 中的内容
If your list of files which has TODO in them is stored in a file, say named "file_list.txt", run:
This will retrieve a list of all the lines containing "TODO" string, prepended with filename and line #, and store that in TODOs.txt
Riley Lark(和 EdoDodo)的答案可能是最简洁的,但是为了不在输出中显示字面的“TODO”文本,您可以使用 ack:
输出:
如果您想要一些稍微不同的格式,那么添加
--no-group
选项将提供:Riley Lark's (and EdoDodo's) answers are probably the most concise, however to not have the literal "TODO" text to show up in the output, you could use ack:
Output:
If you wanted some slightly different formatting then adding the
--no-group
option would provide:这将在当前目录下的任何文件中递归地查找任何带有“// TODO”的行:
这会稍微清理输出:
请注意,如果源代码文件名中存在冒号(:),这可能会中断。
您可以将输出放入具有最终重定向的文件中。
编辑:
这更好:
This will recursively find any line with '// TODO' in any file under the current directory:
This cleans up the output a bit:
Note that this might break if there are colons (:) in your source code file names.
You can put the output in a file with a final redirection.
EDIT:
This is even better:
这是一个命令,它将查找您所在目录及其子目录中的所有 TODO,并将它们放入文本文件中:
编辑:
要删除之前不必要的输出,您可以使用此 命令命令改为:
Here's a command that will find all the TODOs in the directory you're in, and it's subdirectories, and put them in a text file:
EDIT:
To remove the unnecessary output before it, you could use this command instead:
遇到了同样的问题,所以想出了一个简单的 python 脚本来使用 git grep 来完成它......
Hade the same issue so came up with a simple python script to do it using git grep...