Appending a line to a file only if it does not already exist

后端 未结 10 1245
深忆病人
深忆病人 2020-11-30 16:44

I need to add the following line to the end of a config file:

include \"/configs/projectname.conf\"

to a file called lighttpd.conf

10条回答
  •  广开言路
    2020-11-30 17:10

    use awk

    awk 'FNR==NR && /configs.*projectname\.conf/{f=1;next}f==0;END{ if(!f) { print "your line"}} ' file file
    

提交回复
热议问题