我有一个空白行的文件,但是以下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.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
proe_wfpdmo_pdm_matfnc_b+PDM_MTLFNC+wfpdmo_pdm_matfnc_b.txt@proe.wfpdmo_pdm_matfnc_b
proe_wfpdmo_proe_resparam+PDM_PARM+wfpdmo_proe_resparam.txt@proe.wfpdmo_proe_resparam
proe_wfpdmo_proe_restrparam+PDM_PARM+wfpdmo_proe_restrparam.txt@proe.wfpdmo_proe_restrparam
proe_wfpdmo_proe_restrparam_b+PDM_PARM+wfpdmo_proe_restrparam_b.txt@proe.wfpdmo_proe_restrparam_b
proe_wfpdmo_proe_restrparam_b+PDM_PARM+wfpdmo_proe_restrparam_b_2.txt@proe.wfpdmo_proe_restrparam_b
答案 0 :(得分:1)
这是删除所有行:
-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
答案 1 :(得分:0)
你可以使用awk
$ awk 'NF && !/^(>|END)/ && !/#.*/' file