I've got a large apache log file and I have to filter might leave only (inside a new file) the log from the certain IP: 192.168.1.102
I attempt by using this command:
sed -e "/^192.168.1.102/d" < input.txt > output.txt
But "/d" removes individuals records, and that i needt to depart them.
How about using
cat input.txt | grep -e "^192.168.1.102" > output.txt
EDIT: As noted within the comments below, getting away the dots within the regex is essential to really make it correct. Getting away within the regex is performed with backslashes:
cat input.txt | grep -e "^192\.168\.1\.102" > output.txt
sed -n 's/^192\.168\.1\.102/&/p'
sed is faster than grep on my small machines
I believe using grep is the greatest solution but when you need to use sed it can be done such as this:
sed -e '/^192\.168\.1\.102/b' -e 'd'
The b command will skip all following instructions when the regex matches and also the d command will thus remove the lines that the regex didn't match.