简体   繁体   English

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

[英]adding line numbers to the end on a line in notepad++

Can I use notepad++ to add a line number(or any number) and increment then for each line using regex .I know I can do this at the beginning of the line but how eo I do it at the end of the line? 我可以使用notepad ++添加行号(或任何数字),然后使用regex为每行递增 。我知道我可以在行首执行此操作 ,但是我如何在行末执行eo?

[[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-

this is what I want: 这就是我要的:

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

EDIT1 编辑1

Some options with a script/command line: 脚本/命令行的一些选项:

$ 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

By pressing on Alt + move mouse from first line to last line, you select the last column. 通过按Alt +将鼠标从第一行移到最后一行,可以选择最后一列。

Then Alt + C , in the dialog box, choose initial number 1 and increment 1 then click OK . 然后,在对话框中, 按Alt + C ,选择初始编号1 ,然后递增1然后单击确定

If the lines are not the same length, select the column after the longest one. 如果行的长度不同,请选择最长的一列。 After you have inserted the numbers, just do a replacement: \\s*(\\d+)$ --> $1 插入数字后,只需进行替换: \\s*(\\d+)$ -> $1

You can use the solution provided by the linked QA, then do a little regex to put your line numbers to the end: 您可以使用链接的质量检查人员提供的解决方案,然后做一点正则表达式将行号放在最后:

  • Install TextFX plugin, if not already done 安装TextFX插件(如果尚未完成)
  • Mark your whole file content 标记整个文件内容
  • TextFX -> TextFX Tools -> Insert Line Numbers TextFX-> TextFX工具->插入行号
  • Open the replace dialog (CTRL + H) 打开替换对话框(CTRL + H)
  • Check regular expressions 检查正则表达式
  • Search pattern: 0+(\\d+) (.*) 搜索模式: 0+(\\d+) (.*)
  • Replace pattern: $2$1 替换图案:$ 2 $ 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM