这是我用来匹配变量中的字符串并删除匹配项所在的行的方法:
sed -i '/'"$domainAndSuffix.cfg"'/d' /etc/file
我想知道如何匹配变量中的字符串,但如果文件中的匹配项具有 . 紧邻它在左边,那么它不会删除这一行并继续浏览文件,直到找到没有 .
示例文件内容:
happy.domain.com
pappy.domain.com
domain.com
要匹配的字符串:
domain.com
所需的文件输出:
happy.domain.com
pappy.domain.com
*编辑:实际文件内容:
cfg_file=/etc/nagios/objects/http_url/bob.ca.cfg
cfg_file=/etc/nagios/objects/http_url/therecord.com.cfg
cfg_file=/etc/nagios/objects/http_url/events.therecord.com.cfg
cfg_file=/etc/nagios/objects/http_url/read.therecord.com.cfg
cfg_file=/etc/nagios/objects/http_url/wheels.ca.cfg
cfg_file=/etc/nagios/objects/http_url/used-vehicle-search.autos.ca.msn.com.cfg
cfg_file=/etc/nagios/objects/http_url/womensweekendshow.com.cfg
cfg_file=/etc/nagios/objects/http_url/yorkregion.com.cfg
cfg_file=/etc/nagios/objects/http_url/yourclassifieds.ca.cfg