在记事本++中的行末尾添加行号

时间:2016-10-24 21:39:27

标签: regex notepad++

我可以使用notepad ++添加行号(或任何数字),然后使用正则表达式增加每行的行数。我知道我可以在行的开头做this但是我是怎么做到最后的?

[[33mab18ba3884244e99d99122e788062b2aaf6ba372[[m commit-
[[33m9625c19e03a747457162d7c0274d75b154a0b926[[m commit-
[[33m8668df12af9eee540cc29f9deb6d31d873bb8f24[[m commit-
[[33m8315cd7962c902d39160fcf2fd018f249e7cf744[[m commit-
[[33m3bcecc602a70fb60324777831d51c81b6f9ccaa7[[m commit-
[[33m0485a39c37e72eabb4003e07a6b8cbae7a0d4e25[[m commit-
[[33m9d3b04a7bcbb82be8b6b7882511f8133745c93b6[[m commit-
[[33m22c259497571390fdd1461f0dd6b77244851984b[[m commit-
[[33m39fb965fc245be55bb86491b5871dd2def08fdf4[[m commit-
[[33m299f6bb77e922d707c9981a48d4d75f57b724719[[m commit-
[[33me7285377d7afc08c7a5fb0ca44154d2de7e1d275[[m commit-
[[33mb3360786ef13044d13b6e58c2239cce5595a1abf[[m commit-
[[33m9af4c134e0d239d1c34fc6bb6087f0473c187fd5[[m commit-
[[33md55ac3370f506a4bbf8a4690b9285e5de9c6a671[[m commit-
[[33me50ef5f58b18d05c36343114804d8be180d26bcb[[m commit-
[[33m962e4a8de7649e06df29f9058a600f8318caf023[[m commit-
[[33m37f5363f62a3f973fe6e0d516e47b4324186d998[[m commit-
[[33m0033e32339e4dc0cce8bd208d43b18a4e9ab43d9[[m commit-
[[33m345239c740a408826f1df0dc5592d5d6b355f019[[m commit-
[[33m8c85bf2592f52302ff389a5b6af4127fbe04c73b[[m commit-
[[33ma4077b6c2b6a491af72ae3afc3b5c6260090b605[[m commit-

这就是我想要的:

[[33mab18ba3884244e99d99122e788062b2aaf6ba372[[m commit-1
[[33m9625c19e03a747457162d7c0274d75b154a0b926[[m commit-2
[[33m8668df12af9eee540cc29f9deb6d31d873bb8f24[[m commit-3
...
[[33ma4077b6c2b6a491af72ae3afc3b5c6260090b605[[m commit-N

EDIT1

脚本/命令行的一些选项:

$ cat number_at_line_end
[[33mab18ba3884244e99d99122e788062b2aaf6ba372[[m commit-
...
[33m345239c740a408826f1df0dc5592d5d6b355f019[[m commit-
[[33m8c85bf2592f52302ff389a5b6af4127fbe04c73b[[m commit-
[[33ma4077b6c2b6a491af72ae3afc3b5c6260090b605[[m commit-

$ awk -v i=1 '{print $0 i++ }' number_at_line_end
[[33mab18ba3884244e99d99122e788062b2aaf6ba372[[m commit-1
[[33m9625c19e03a747457162d7c0274d75b154a0b926[[m commit-2
[[33m8668df12af9eee540cc29f9deb6d31d873bb8f24[[m commit-3
...
[[33m345239c740a408826f1df0dc5592d5d6b355f019[[m commit-19
[[33m8c85bf2592f52302ff389a5b6af4127fbe04c73b[[m commit-20
[[33ma4077b6c2b6a491af72ae3afc3b5c6260090b605[[m commit-21

$ awk '{print $0 i++ }' number_at_line_end
[[33mab18ba3884244e99d99122e788062b2aaf6ba372[[m commit-0
[[33m9625c19e03a747457162d7c0274d75b154a0b926[[m commit-1
[[33m8668df12af9eee540cc29f9deb6d31d873bb8f24[[m commit-2
...
[[33m8c85bf2592f52302ff389a5b6af4127fbe04c73b[[m commit-19
[[33ma4077b6c2b6a491af72ae3afc3b5c6260090b605[[m commit-20

## counting down
$ a="$(wc -l number_at_line_end | cut -f1 -d' ')" | awk -v i="$a" '{print $0 i-- }' number_at_line_end
[[33mab18ba3884244e99d99122e788062b2aaf6ba372[[m commit-21
[[33m9625c19e03a747457162d7c0274d75b154a0b926[[m commit-20
...
[[33m345239c740a408826f1df0dc5592d5d6b355f019[[m commit-3
[[33m8c85bf2592f52302ff389a5b6af4127fbe04c73b[[m commit-2
[[33ma4077b6c2b6a491af72ae3afc3b5c6260090b605[[m commit-1

2 个答案:

答案 0 :(得分:2)

Alt +将鼠标从第一行移动到最后一行,选择最后一列。

然后 Alt + C ,在对话框中选择初始编号1并增加1,然后单击确定

如果行长度不同,请选择最长行后的列。插入数字后,只需进行替换:\s*(\d+)$ - > $1

答案 1 :(得分:1)

您可以使用链接QA提供的解决方案,然后使用一些正则表达式将行号放到最后:

  • 安装TextFX插件(如果尚未安装)
  • 标记您的整个文件内容
  • TextFX - > TextFX工具 - >插入行号
  • 打开替换对话框(CTRL + H)
  • 检查正则表达式
  • 搜索模式:0+(\d+) (.*)
  • 替换模式:$ 2 $ 1