开发者

remove blank lines not working in sed

I have a file which has blank lines but the following sed command is not working:

sed -e 's/#.*//' -e '/^END/ d' -e '/^>/ d' -e '/^$*/ d' auto.txt > a.txt

It works but when I add the blank line thing it removes everything and i get empty file

Sample

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

output needed

a.txt

proe_wfpdmo_wsabar_pdmactions+PDM_MDHTASM+wfpdmo_wsabar_pdmactions.txt@proe.wfp开发者_开发技巧dmo_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


This is removing all lines:

-e '/^$*/ d'

Remove the asterisk:

-e '/^$/d'

This will give you:

$ 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


you can use awk

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜