如何替换固定长度的字母数字字符? [英] How to replace fixlength alphanumeric character?
本文介绍了如何替换固定长度的字母数字字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试仅使用 sed 替换固定长度的字母数字后的字符串.
I am trying to replace String after alphanumeric of fix length only using sed.
testing-1xs-a-2x-782b1x9.abc.txt
testing-12a-b-2y-486eee2.bcd.txt
testing-1a-c-2z-b62cx7d.cde.txt
我试过这个命令 - sed 's/[a-zA-Z0-9]{7}.*//g'
文件
I tried this command - sed 's/[a-zA-Z0-9]{7}.*//g'
file
预期输出:
testing-1xs-a-2x
testing-12a-b-2y
testing-1a-c-2z
推荐答案
你可以试试看吗.
awk --re-interval '{sub(/-[[:alnum:]]{7}.*/,"")} 1' Input_file
如果您的 awk
是新版本,您可以从上面的代码中删除 --re-interval
.
In case your awk
is of new version you could remove --re-interval
from above code.
在 sed
中,您可以尝试以下操作.
In sed
you could try following.
sed -E 's/-[[:alnum:]]{7}.*//' Input_file
这篇关于如何替换固定长度的字母数字字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文