Formatting port scan output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Formatting port scan output
# 1  
Old 03-18-2011
Formatting port scan output

I need to format port scan output for input into another app.

This is what I have;

Code:
1025/tcp
1521/tcp
2301/tcp
2381/tcp
3191/tcp
3389/tcp
5938/tcp
47001/tcp
54321/tcp
21/tcp
80/tcp
135/tcp
139/tcp
445/tcp
1025/tcp

I want to chop the "/tcp" off, run it through uniq so that I only have the unique ports and then stack the output like below comma separated

Code:
1521, 2301, 2381, 3191, 3389, 5938, 47001, 54321, 21

Thanks!
# 2  
Old 03-18-2011
Code:
nawk -F/ '{a[$1]}END{for(i in a) printf("%c%s",j++?OFS:"", i);print ""}' OFS=, myFile

# 3  
Old 03-18-2011
Something like...

Code:
$ cut -d'/' -f1 < sample4.txt | sort -n | uniq -u | tr "\n" ","
21,80,135,139,445,1521,2301,2381,3191,3389,5938,47001,54321,

# 4  
Old 03-18-2011
Perfect, thanks
# 5  
Old 03-18-2011
Another approach:
Code:
awk -F\/ '{s=s?s ", " $1:$1}END{print s}' file

Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Use awk to turn character to newline then scan output

i have a datafile (data.txt) that has the following data: #Beginner`echo... (4 Replies)
Discussion started by: SkySmart
4 Replies

2. Shell Programming and Scripting

Formatting ls output

I am using find and ls to search for "warez" files on my server. find /home/ -regex ".*\.\(avi\|mp3\|mpeg\|mpg\|iso\)" -print0 | xargs -0 ls -oh This command produces this: -rw-r--r-- 1 1000 3.2M Feb 18 2009 /home/user/public_html/lupus.mp3 I want to only get this 3.2M... (4 Replies)
Discussion started by: bonrad
4 Replies

3. Shell Programming and Scripting

port scan shell script

Hi, Can any one please suggest me commands for making port scan shell script. (3 Replies)
Discussion started by: nrbhole
3 Replies

4. UNIX for Advanced & Expert Users

Please let me know Regarding Port Scan

Can any one please let me know below ones 1) How to Perform the Port Scan in Solaris Environment and how to block the unwanted Ports. 2) How to know whether particular Port is listning the requests or not? Thanks Ramkumar.B (7 Replies)
Discussion started by: myramkumar
7 Replies

5. UNIX for Dummies Questions & Answers

unix program that can port scan a c block of ips for proxies

can anyone tell me a unix program that can port scan a c block of ips for proxies? a fast one, with reliable results, that can load an ip list, or set an ip range, and specify ports thanks! (1 Reply)
Discussion started by: user
1 Replies
Login or Register to Ask a Question