LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   awk not parse the output of nc command! (https://www.linuxquestions.org/questions/linux-general-1/awk-not-parse-the-output-of-nc-command-905003/)

mythcat 09-26-2011 02:09 AM

awk not parse the output of nc command!
 
I try to parse the output of nc command
This is code :
Code:

nc -v  localhost -z 6660-6661,80 | awk '/succeeded/'
I think is not awk problem ...
Can somebody help me understand what happen or how to use it?
Thank you . Regards .

EricTRA 09-26-2011 02:14 AM

Hi,

If you want to get the list of succeeded connections, use grep instead of awk like this:
Code:

nc -v  localhost -z 6660-6661,80 | grep "succeeded"
Kind regards,

Eric

colucix 09-26-2011 03:31 AM

To me the syntax of the port argument is invalid and no standard output is piped to awk. Looking at the man page of nc, they don't specify you can use a comma to separate the list of ports to scan.

mythcat 09-26-2011 09:09 AM

This is just one example with comma . My problem is output of nc command.
This output not parse with awk.
Quote:

Originally Posted by colucix (Post 4482362)
To me the syntax of the port argument is invalid and no standard output is piped to awk. Looking at the man page of nc, they don't specify you can use a comma to separate the list of ports to scan.


colucix 09-26-2011 09:16 AM

The problem cannot be awk, but what passes through the pipe as standard output. Some commands send terminal output to standard error, so that a redirection is needed, but nc is not one of these. What do you get by running the nc command alone (without piping to awk)?

mythcat 09-30-2011 02:45 AM

Quote:

Originally Posted by colucix (Post 4482576)
The problem cannot be awk, but what passes through the pipe as standard output. Some commands send terminal output to standard error, so that a redirection is needed, but nc is not one of these. What do you get by running the nc command alone (without piping to awk)?

... running command alone will not allow me to parse the output.

EricTRA 09-30-2011 03:00 AM

Quote:

Originally Posted by mythcat (Post 4486233)
... running command alone will not allow me to parse the output.

Hi,

That wasn't the question colucix asked. He was asking you what the output of the nc command is (without the pipe). Run the nc command without piping it and post the output. I'm kind of sure that you'll need to put a space after the comma (at least on my Debian I had to). If I don't have a space after the comma only the first port queried gives output, disregarding the rest. With a space I get all ports from a list. Next we'll worry about the output filtering.

Kind regards,

Eric


All times are GMT -5. The time now is 05:11 PM.