我正在寻找有关搜索和替换文件中的字符串的小帮助。
我的文件内容
hostssl all all 192.168.10.1/16 pam pamservice=postgresql clientcert= 1
hostssl all all 192.168.10.2/16 pam pamservice=postgresql clientcert=1
hostssl all all 192.168.10.3/16 pam pamservice=postgresql clientcert= 1
hostssl all all 192.168.10.4/16 pam pamservice=postgresql clientcert= 1
hostssl all all 192.168.20.1/16 pam pamservice=postgresql clientcert=1
hostssl all all 192.168.20.2/16 pam pamservice=postgresql clientcert=1
hostssl all all 192.168.20.3/16 pam pamservice=postgresql clientcert=1
hostssl all all 192.168.10.5/16 pam pamservice=postgresql clientcert=1
hostssl all all 192.168.10.6/16 pam pamservice=postgresql clientcert=1
hostssl all all 192.168.10.7/16 pam pamservice=postgresql clientcert= 1
我尝试使用以下命令
sed -i "s/clientcert=*1/clientcert=verify-full/g" pg_hba.conf
它的作用不是预期的结果
hostssl all all 192.168.10.1/16 pam pamservice=postgresql **clientcert= 1**
hostssl all all 192.168.10.2/16 pam pamservice=postgresql clientcert=verify-full
hostssl all all 192.168.10.3/16 pam pamservice=postgresql **clientcert= 1**
hostssl all all 192.168.10.4/16 pam pamservice=postgresql **clientcert= 1**
hostssl all all 192.168.20.1/16 pam pamservice=postgresql clientcert=verify-full
hostssl all all 192.168.20.2/16 pam pamservice=postgresql clientcert=verify-full
hostssl all all 192.168.20.3/16 pam pamservice=postgresql clientcert=verify-full
hostssl all all 192.168.10.5/16 pam pamservice=postgresql clientcert=verify-full
hostssl all all 192.168.10.6/16 pam pamservice=postgresql clientcert=verify-full
hostssl all all 192.168.10.7/16 pam pamservice=postgresql clientcert= 1
请让我知道通过忽略“=”和1”之间的空格将“clientcert= 1”替换为“clientcert=verify-full”的最佳替代方法
答案1
我找到了答案。下面的代码对我有用
sed -i "s/clientcert=[[:space:]]*1/clientcert=verify-full/g" pg_hba.conf