Reputation: 118
I have file which contains list of IPs. Among those IPs I want to remove IPs with 10.0.1.x series.
So to check those IPs I used following command
grep -F "10.0.1." IPList.txt
However how to remove those IPs from IPList.txt as I have to provide this IPList.txt file as an input to another script.
Upvotes: 0
Views: 34
Reputation: 88583
With GNU sed:
sed '/^10\.0\.1\./d' IPList.txt
If you want to edit your file "in place" use sed's option -i
.
Upvotes: 2
Reputation: 201439
One possible option is to use grep -v
, the GNU Grep 2.23 man
page says, in part,
-v --invert-match Invert the sense of matching, to select non-matching lines. (-v is specified by POSIX.)
something like
grep -v "10.0.1." < IPList.txt > IPList-nolocal.txt
which will copy IPList.txt
to IPList-nolocal.txt
excluding any lines that match 10.0.1.
If you want to see the output as you run it, you could use the tee
command (the linked Wikipedia article begins normally used to split the output of a program so that it can be both displayed and saved in a file)
grep -v "10.0.1." < IPList.txt | tee IPList-nolocal.txt
Upvotes: 2