简体   繁体   English

使用 Sed 和 Regex 将字符串替换为空格

[英]Replace strings with space using Sed and Regex

I want to replace all occurrences of {{password}} or {{ password }} or {{password }} in files with some string using sed i am able to remove with know number of spaces, but could not remove all combinations.我想使用sed将文件中所有出现的 {{password}} 或 {{ password }} 或 {{password }} 替换为一些字符串,我可以用已知的空格数删除,但无法删除所有组合。

i could replace using, but not all combinations我可以替换使用,但不是所有组合

sed -i -e "s/{{ password }}/$password/g" test.sql

If the number of spaces is arbitrary, then you could search for zero or more spaces ( * ) instead of just one space (如果空格数是任意的,那么您可以搜索零个或多个空格 ( * ) 而不是一个空格 ( ) with something like {{ *password *}} . ) 类似{{ *password *}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM