gpt4 book ai didi

regex - (GNU)Sed : how to replace any character from nth character to nth+10?

转载 作者:行者123 更新时间:2023-11-29 09:20:30 27 4
gpt4 key购买 nike

我需要替换字符串中第 10 到第 20 个字符,如下所示:

123456789012345678901234567890

到目前为止我已经尝试过:

一个)

仅适用于第 10 个字符: echo “123456789012345678901234567890” | sed 's/./X/10'

b)不适用于范围:

echo "123456789012345678901234567890"  | sed 's/./X/10,20'
echo "123456789012345678901234567890" | sed 's/./X/10\,20'
echo "123456789012345678901234567890" | sed 's/./X/\{10,20\}'
echo "123456789012345678901234567890" | sed 's/./X/\{10\,20\}'

不工作,我得到错误

unknown option to `s'

所以 - 问题是 - 我如何让它工作:

回显“123456789012345678901234567890” | sed 's/./X/10,20'

最佳答案

尝试:

$ sed -r "s/^(.{9})(.{11})/\1XXXXXXXXXX/" <<< 123456789012345678901234567890
123456789XXXXXXXXXX1234567890

关于regex - (GNU)Sed : how to replace any character from nth character to nth+10?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22226521/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com