删除sed中不起作用的空行

删除sed中不起作用的空行,sed,Sed,我有一个文件有空行,但以下sed命令不起作用: sed -e 's/#.*//' -e '/^END/ d' -e '/^>/ d' -e '/^$*/ d' auto.txt > a.txt 它工作,但是当我添加空白行的时候,它删除了所有的东西,我得到了空文件 样品 auto.txt >#begin wildfire_pdm_x10 #wildfire_test server pdml x10 mode=PDM_MDHTASM clean_cache proe_wfpdmo

我有一个文件有空行,但以下sed命令不起作用:

sed -e 's/#.*//' -e '/^END/ d' -e '/^>/ d' -e '/^$*/ d' auto.txt > a.txt
<>它工作,但是当我添加空白行的时候,它删除了所有的东西,我得到了空文件

样品 auto.txt

>#begin wildfire_pdm_x10
#wildfire_test server pdml x10 mode=PDM_MDHTASM clean_cache
proe_wfpdmo_wsabar_pdmactions+PDM_MDHTASM+wfpdmo_wsabar_pdmactions.txt@proe.wfpdmo_wsabar_pdmactions
END
#wildfire_test server pdml x10 mode=PDM_MDTTB clean_cache
proe_wfpdmo_wstbar_pdmactions+PDM_MDTTB+wfpdmo_wstbar_pdmactions.txt@proe.wfpdmo_wstbar_pdmactions
END
所需产量 a、 文本

你可以用awk

$ awk 'NF && !/^(>|END)/ && !/#.*/' file
你可以用awk

$ awk 'NF && !/^(>|END)/ && !/#.*/' file

这将删除所有行:

-e '/^$*/ d'
删除星号:

-e '/^$/d'
这将为您提供:

$ sed -e 's/#.*//' -e '/^END/ d' -e '/^>/ d' -e '/^$/ d' auto.txt
proe_wfpdmo_wsabar_pdmactions+PDM_MDHTASM+wfpdmo_wsabar_pdmactions.txt@proe.wfpdmo_wsabar_pdmactions
proe_wfpdmo_wstbar_pdmactions+PDM_MDTTB+wfpdmo_wstbar_pdmactions.txt@proe.wfpdmo_wstbar_pdmactions

这将删除所有行:

-e '/^$*/ d'
删除星号:

-e '/^$/d'
这将为您提供:

$ sed -e 's/#.*//' -e '/^END/ d' -e '/^>/ d' -e '/^$/ d' auto.txt
proe_wfpdmo_wsabar_pdmactions+PDM_MDHTASM+wfpdmo_wsabar_pdmactions.txt@proe.wfpdmo_wsabar_pdmactions
proe_wfpdmo_wstbar_pdmactions+PDM_MDTTB+wfpdmo_wstbar_pdmactions.txt@proe.wfpdmo_wstbar_pdmactions

是的,你可以。但这并没有告诉你“空行”有什么问题,也没有说明如何解决它。是的,你可以。但这并没有告诉你“空行”有什么问题,也没有说明如何解决它。