Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete whole line NOT containing given string

Is there a way to delete the whole line if it contains specific word using sed? i.e. I have the following:

aaa bbb ccc

qqq fff yyy

ooo rrr ttt

kkk ccc www

I want to delete lines that contain 'ccc' and leave other lines intact. In this example the output would be:

qqq fff yyy

ooo rrr ttt

All this using sed. Any hints?

like image 816
user1240622 Avatar asked Feb 24 '26 11:02

user1240622


1 Answers

sed -n '/ccc/!p'

or

sed '/ccc/d'
like image 116
hroptatyr Avatar answered Feb 27 '26 03:02

hroptatyr