I used following command for port scanning of my machinenc -zv 192.168.1.1 1-100but I want to filter only succeeded message from  following output.Hence i used the following command nc -zv 192.168.1.1 1-100|grep succeededBut no use, still it shows full output nc: connect to 192.168.1.1 port 1 (tcp) failed: Connection refusednc: connect to 192.168.1.1 port 2 (tcp) failed: Connection refusednc: connect to 192.168.1.1 port 3 (tcp) failed: Connection refusednc: connect to 192.168.1.1 port 4 (tcp) failed: Connection refusednc: connect to 192.168.1.1 port 5 (tcp) failed: Connection refusednc: connect to 192.168.1.1 port 6 (tcp) failed: Connection refusednc: connect to 192.168.1.1 port 7 (tcp) failed: Connection refusednc: connect to 192.168.1.1 port 8 (tcp) failed: Connection refusednc: connect to 192.168.1.1 port 9 (tcp) failed: Connection refused
How to filter the success message when using nc port scan
grep;nc
Change your command to this:nc -zv 192.168.1.1 1-100 2>&1 | grep succeeded2>&1 causes stderr of a program to be written to the same file descriptor as stdout. nc writes to stderr by default, pipe will only get stdout hence grep will miss the data. See section 3.5 here for more info All about redirection.