删除插入符号并向寻呼机号码添加括号

删除插入符号并向寻呼机号码添加括号

我有这样的字符串

NE234GJKLKU,*9^789098
NE345HJsdfe,*1^534656
YBKJNJKHBKK,*1^987654
UTGHNKOIUYO,*1^123421
ERTYUIJHGLK,*1^456666

我希望成为:

NE234GJKLKU,*(978)-9098
NE345HJsdfe,*(153)-4656
YBKJNJKHBKK,*(198)-7654
UTGHNKOIUYO,*(112)-3421
ERTYUIJHGLK,*(145)-6666

有什么建议么?

答案1

尝试sed

sed -r -e 's/\^//g;s/^.{13}/&(/;s/^.{17}/&)-/' file

NE234GJKLKU,*(978)-9098
NE345HJsdfe,*(153)-4656
YBKJNJKHBKK,*(198)-7654
UTGHNKOIUYO,*(112)-3421
ERTYUIJHGLK,*(145)-6666

答案2

我认为这会做:

sed -E 's/(.)\^(..)/(\1\2)-/' file

答案3

另一个sed解决方案:

$ sed 's,*,*(,g' FILE | sed -E 's,([0-9])\^([b0-9])([0-9]),\1\2\3)-,g'
NE234GJKLKU,*(978)-9098
NE345HJsdfe,*(153)-4656
YBKJNJKHBKK,*(198)-7654
UTGHNKOIUYO,*(112)-3421
ERTYUIJHGLK,*(145)-6666

单线:

$ sed -E 's,\*,*(,g;s,([0-9])\^([b0-9])([0-9]),\1\2\3)-,g' FILE
NE234GJKLKU,*(978)-9098
NE345HJsdfe,*(153)-4656
YBKJNJKHBKK,*(198)-7654
UTGHNKOIUYO,*(112)-3421
ERTYUIJHGLK,*(145)-6666

相关内容