<VirtualHost 192.168.1.158:80>
DocumentRoot /home/ten
ServerName ten.com
</VirtualHost>
<VirtualHost 192.168.1.158:80>
DocumentRoot /home/sachin
ServerName sachin.com
</VirtualHost>
<VirtualHost 192.168.1.158:80>
DocumentRoot /home/yuvraj
ServerName yuvraj.com
</VirtualHost>
<VirtualHost 192.168.1.158:80>
DocumentRoot /home/checking
ServerName checking.com
</VirtualHost
~
I want to delete sachin.com from the above file so the output look like
<VirtualHost 192.168.1.158:80>
DocumentRoot /home/ten
ServerName ten.com
</VirtualHost>
<VirtualHost 192.168.1.158:80>
DocumentRoot /home/yuvraj
ServerName yuvraj.com
</VirtualHost>
<VirtualHost 192.168.1.158:80>
DocumentRoot /home/checking
ServerName checking.com
</VirtualHost
~
Please how to do this using sed command
how about this awk code?
awk '$0!~/sachin.com/' RS="\n\n" ORS="\n\n" file
cgkmal
March 26, 2011, 3:58am
3
Try with the opposite of a known sed oneliner ("print paragraph if it contains pattern"), I've adapted it to your
case ("print paragraph if it not contains pattern").
I'm not sure exactly how it works, but it does:
sed -e '/./{H;$!d;}' -e 'x;/sachin.com/d;' inputfile
or more compressed:
sed -e '/./{H;$!d;};x;/sachin.com/d;' inputfile
Reference: http://sed.sourceforge.net/sed1line.txt
Regards
ctsgnb
March 26, 2011, 5:21am
4
... and to avoid the adding of the empty new line you should use h instead of H for the first line.
sed '1{/./h;d;};/./{H;$!d;};x;/sachin.com/d;' infile
tene
March 28, 2011, 2:15am
5
awk 'BEGIN{RS="\n\n"}{if($6 != "sachin.com")print $0"\n";}' inputfile
xoops
March 28, 2011, 6:15am
6
If your grep supports -p flag.
grep -vp "sachin.com" inputfile