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.
我想找到所有包含self.vars['stuff']该文本的文件并将其替换为self.v.stuff.
self.vars['stuff']
self.v.stuff
我曾尝试使用:sed -e "s/self.vars\['/self.v./" -e "s/'\]//",但这会影响碰巧包含]的其他行......
sed -e "s/self.vars\['/self.v./" -e "s/'\]//"
]
有任何想法吗?
使用反向引用。这适用于 sed,假设您只使用单引号作为键:
s/self\.vars\['\([^]]\+\)'\]/self.v.\1/g