开发者

sed question insert colons

开发者 https://www.devze.com 2023-02-28 20:51 出处:网络
Hello I want to use sed to 开发者_如何学Gosearch a file for 3-5 alpha chars followed by 3 numbers and insert a colon after the first alpha char and a colon before the numbersUsing GNU sed on Ubuntu 10

Hello I want to use sed to 开发者_如何学Gosearch a file for 3-5 alpha chars followed by 3 numbers and insert a colon after the first alpha char and a colon before the numbers


Using GNU sed on Ubuntu 10.04.2 LTS:

sed -r -e 's/([a-zA-Z]{3,5})([0-9]{3})/\1:\2/g'

EDIT: Misread the OP's question. Better answer:

sed -r -e 's/([a-zA-Z])([a-zA-Z]{2,4})([0-9]{3})/\1:\2:\3/g'
0

精彩评论

暂无评论...
验证码 换一张
取 消