LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 09-26-2011, 02:09 AM   #1
mythcat
Member
 
Registered: Dec 2007
Location: Bucharest
Distribution: Debian;Fedora
Posts: 63

Rep: Reputation: 15
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 .
 
Old 09-26-2011, 02:14 AM   #2
EricTRA
Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 18 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290
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
 
Old 09-26-2011, 03:31 AM   #3
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,458

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
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.
 
Old 09-26-2011, 09:09 AM   #4
mythcat
Member
 
Registered: Dec 2007
Location: Bucharest
Distribution: Debian;Fedora
Posts: 63

Original Poster
Rep: Reputation: 15
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 View Post
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.
 
Old 09-26-2011, 09:16 AM   #5
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,458

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
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)?
 
Old 09-30-2011, 02:45 AM   #6
mythcat
Member
 
Registered: Dec 2007
Location: Bucharest
Distribution: Debian;Fedora
Posts: 63

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by colucix View Post
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.
 
Old 09-30-2011, 03:00 AM   #7
EricTRA
Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 18 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290
Quote:
Originally Posted by mythcat View Post
... 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
 
  


Reply

Tags
awk


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Using bash command to execute output of awk sylye Programming 12 04-03-2011 04:37 AM
[shell script] execute command and parse output stoiss Programming 2 01-26-2009 01:49 AM
How do I parse the output of a command that output to standard out? gauol Programming 9 01-17-2008 01:54 PM
How to use awk command to parse fields in a line johnsanty Programming 9 05-25-2006 09:56 PM
how to pipe and parse output of a command learnfast Linux - Newbie 2 06-15-2005 04:55 AM


All times are GMT -5. The time now is 02:09 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration