我想在文件中查找一个字符串:
例子
https://google.com/first/second/45683
我想重写它并保留原来的行:
https://google.com/first/second/45683 https://yahoo.com/third/fourth/45683
我尝试过几次
sed -r 's@https://google.com/first/second/([a-Z0-9]+)@yahoo.com/third/fourth/\1@' 文件.txt 输出: yahoo.com/third/fourth/45683
它进行了重写,但没有保留原始行。
另一次尝试
sed -r 'a\s@https://google.com/first/second/([a-Z0-9]+)@yahoo.com/third/fourth/\1@' 文件.txt 输出: https://google.com/first/second/45683 https://google.com/first/second/([a-Z0-9]+)@yahoo.com/third/fourth/1@
它附加两行但不会重写第二行。