如果引号后的第一个符号是点,如何删除每一行?

如果引号后的第一个符号是点,如何删除每一行?

如果示例中引号后的第一个符号是点,我需要从配置中删除每一行:

local-zone: ".test.com" redirect <- remove
local-zone: "www.test.com" redirect <- don't remove
local-zone: "test.com" redirect <- don't remove

我尝试过使用 sed 但没有成功:

sed -i '/".*\..*"/d' file.txt

答案1

如果你有sed,你grep也有;)

$ grep -Ev  '"\.[^"]+"' file .txt | sponge file.txt
local-zone: "www.test.com" redirect <- don't remove
local-zone: "test.com" redirect <- don't remove

sed

$ sed -i -E '/"\.[^"]+"/d' file
local-zone: "www.test.com" redirect <- don't remove
local-zone: "test.com" redirect <- don't remove

相关内容