Delete lines based on Rules

Hi My requirement is very simple .

I juts need to delte some lines from a file.

here comes theactual scenario

I have some data in file like say

 
srinivasa prabhu kumar antony 
srinivas king prabhu antony 
srinivas prabhu king yar venkata 
venkata kingson srinivas prabhu 
prabhu srinivas prabhu kingson 

I want to delete the lines which contain both the words srinivas and prabhu.

please help

You can do this using sed with two nested ranges:

sed '/srinivas/ {
                  /prabhu/d
                }' /path/to/input

I hope this helps.

bakunin

Hi i tried this and is not workig ...means the lines are not getting deleted.

Are you getting the output correctly or is that the file remains unchanged? To edit the file inline, you need to use sed -i ...

--ahamed

In your above example, every single line should be deleted, meaning you would have no output at all.

Try also

$ grep -Ev "srinivas.*prabhu|prabhu.*srinivas" file
awk '!(/srinivas/ && /prabhu/)' file

I am not sure if line #1 has a typo srinivasa prabhu kumar antony
If you only like to remove line containing exact words like srinivas and not srinivasa , use this

awk '!(/\<srinivas\>/ && /\<prabhu\>/)' file

Note that the output of sed always goes to <stdout>, which in most cases is the terminal. Try it, watch the output and if you are satisfied redirect it to some file and move this file over the original file:

sed '<commands>' /path/to/input > path/to/output
mv path/to/output /path/to/input

Yes and no. You should not use this feature, even if it is there, which is solely(!) with the GNU-variants of sed .

I hope this helps.

bakunin