如何在一组不同的数字后替换一个字符

How to replace one character after a set of different numbers

我已经尝试解决这个问题一段时间了。

问题示例:

 4946990 stuffandthings.sql.gz
 5005868 Hello there.txt
 1033557 This is an issue.txt
  303500 That_I need help fixing.txt
 8737976 Please help.txt
99737976 Thanks.txt

我想做什么:

 4946990     stuffandthings.sql.gz
 5005868     Hello there.txt
 1033557     This is an issue.txt
  303500     That_I need help fixing.txt
 8737976     Please help.txt
99737976     Thanks.txt

and/or这个:

 4946990 | stuffandthings.sql.gz
 5005868 | Hello there.txt
 1033557 | This is an issue.txt
  303500 | That_I need help fixing.txt
 8737976 | Please help.txt
99737976 | Thanks.txt

基本上我是在尝试替换一组不同数字后的第一个字符。

我从 GitBash 命令 "wc -l" 中获取了这个 "array" 或 "list"(它打印文本文件中的行号数量,以及旁边的文本文件名它)。因此,如果无论如何我都可以使用正则表达式来完成我想要它做的事情,或者如果有一个我在 GitBash 中没有看到的命令可以帮助做到这一点。任何帮助将不胜感激,谢谢。

一种方法是使用以下表达式

^(\d+)([ ]+)(.+)$
# look for digits at the beginning of the line -> group 1
# followed by whitespaces                      -> group 2
# and the rest                                 -> group 3

并将字符串替换为 your_replacement_here ,参见 a demo on regex101.com(注意修饰符,尤其是 m!)。
顺便说一句,这么可爱的昵称+1...

查找:

([0-9])[ ]([a-zA-Z])

替换:

 | 

或: