我有一个包含以下行的文件:
353451word2423157
anotherword
7412yetanother1
3262andherese123anotherline4359013
5342512354325324523andherese123anotherline45913
532453andherese123anotherline413
Run Code Online (Sandbox Code Playgroud)
我想去掉大部分前导和尾随数字(0-9),同时仍然保留 2 个前导和尾随数字,如果有的话......
澄清一下,对于上面的列表,预期的输出是:
51word24
anotherword
12yetanother1
62andherese123anotherline43
23andherese123anotherline45
53andherese123anotherline41
Run Code Online (Sandbox Code Playgroud)
首选工具是 sed 或 awk,但欢迎任何其他建议...
我试过类似的东西sed 's/[0-9]\+$//' | sed 's/^[0-9]\+//',但显然这会去除所有前导和尾随数字......