regex - 使用 sed 命令交换字符串中的第二个和第六个字符
问题描述
我写了一个 sed 命令来交换下面数字中的第二个和第六个字符。
我收到以下错误:
sed: file minor1.sed line 4: invalid reference \9 on `s' command's RHS
我的 sed 命令(script.sed):
s/\(.\){10}/\1\6\3\4\5\2\7\8\9\10/g
我正在使用 sed -r -f script.sed Input.txt 运行命令。
输入.txt -
8668797647
8884747424
3716706006
8662665588
谁能帮我弄清楚为什么我会收到这个错误?
解决方案
试试这个:
sed -E 's/^\(.\)\(.\)\(...\)\(.\)/\1\4\3\2/'
这将捕获编号如下的组中的数字:
Input: abcdefghij
Group: 123334 (the capture group of the digit above)
Result: afcdebghij
只有前 6 位数字被匹配/替换。
推荐阅读
- java - 构造函数需要一个找不到的 bean 类型
- apache-kafka - Kafka 流状态存储是为了什么?
- java - 为什么即使在关闭套接字后我也会收到此错误(java.net.BindException:地址已在使用:NET_Bind)?
- unity3d - 如何统一去除按钮的高亮状态?
- openstack - 新的 Web 应用程序或现有 OpenStack Horizon 的定制
- jestjs - Jest 每个测试套件和跨测试用例初始化和共享对象一次
- python - 在python中检测音频文件是否有语音
- python - 如何重启 PyQt5 应用程序
- python - numpy.r_ 将 1 放在中间
- c# - Unity 2D 'Attack()' 是一个局部函数,因此必须始终有一个主体