英文:
sed command to locate a string containing alphanumeric characters and spaces and perform positional replacement in that string
问题
我想要定位 ARF = 0x000000006e1d9000
并在位置12、13、14等特定位置执行替换,最终结果应该如下:
aadz(mdb awetyi),Lll,Dweuio: mdb 1:00.0  ARF = 0x000000006xxx000
我尝试了这个命令:
sed -i -e 's/\(.\{12\}\)./x/' -e 's/\(.\{13\}\)./x/' -e 's/\(.\{14\}\)./x/' file
但它替换了包含文本的行的开头字符,这不是期望的行为。我无法只定位 ARF = 0x000000006xxx000
。
英文:
i have a file with below line
aadz(mdb awetyi),Lll,Dweuio: mdb 1:00.0  ARF = 0x000000006e1d9000
i want to locate ARF = 0x000000006e1d9000
and perform positional replacement of certain positions like 12,13,14 etc with x. the final result should look like
aadz(mdb awetyi),Lll,Dweuio: mdb 1:00.0  ARF = 0x000000006xxx000
i tried this command
sed -i -e 's/\(.\{12\}\)./x/' -e 's/\(.\{13\}\)./x/' -e 's/\(.\{74\}\)./x/' file
but it replaces the characters from start of the line containing the text which is not desired
I'm unable to locate only ARF = 0x000000006xxx000
答案1
得分: 2
你可以使用以下命令执行此操作:
sed -E 's/(ARF = .{11}).{3}/xxx/g' file
它匹配ARF =
,接下来的11个字符,并将接下来的三个字符替换为xxx
。
请注意,示例中未包含-i
选项:首先测试替代是否按您所需的方式进行。
英文:
You can do it with the following command
sed -E 's/(ARF = .{11}).{3}/xxx/g' file
It matches ARF =
, 11 following symbols and replaces following three symbols with xxx
Option -i
is not included in example: first test to see that replacement is happening like you want.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论