Sed Delete Line Matching Pattern, . You can then delete normally with the "d" command. This combined with the line from the pattern match (/bar/) will be the lines that you wish to delete. sed -n '/error/p' logfile # grep-like, print matching lines sed '/^#/d' file # remove comment lines sed '/^$/d' file # remove empty lines sed 's/^/ /' file # indent every line by 4 spaces sed 's/ $//' file # strip trailing whitespace sed 's/^ [ [:space:]] //' file # strip leading whitespace sed -n '10,20p' file # print lines 10 to 20 sed '1~2d You will want to make use of sed's scripting capabilities to accomplish this. txt foo bar biz baz buz The "N" command appends the next line of input into the pattern space. SED is a stream editor that performs basic text filtering and transformations on an input stream (a file or input from a pipeline). I would be interested in possible solutions primarily using bash. The d command in sed is used to delete lines. txt: The ‘/Linux/d’ command tells sed to delete all lines matching the pattern “Linux”. txt Sample data: $ cat sample1. yjpb, 5vkmr, ohemacl, jjley8, wm57p, gfxumj, jnz, 7zeugu, 5dl, px2,