Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要在模式匹配后替换所有字符直到行尾,同时保持匹配的模式
blhablahPATTERN1XXXXXX
应该读
blhablahPATTERN1STUFFI_WANT_TO_INSERT
到目前为止,我尝试过的所有内容也都删除了 PATTERN1 ......
使用sed
sed
sed -r 's/(PATTERN1).*/\1STUFFI_WANT_TO_INSERT/' file
您需要捕获PATTERN1并\1在替换字符串中使用
\1