LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   remove hostname using sed (https://www.linuxquestions.org/questions/linux-newbie-8/remove-hostname-using-sed-4175415000/)

gilad73 07-05-2012 02:24 AM

remove hostname using sed
 
Hi,
I am trying to format my out put from the results of an nmap command. I would like to basically generate a simple two column list with ip addresses and mac address. I have managed to strip out most of what I don't want with combinations of awk, grep and sed. my problem is not all the rows are the same, some contain host names and other don't. This makes it hard for me to use cut to remove the "Unknown" in the last column. I am struggling with a regex to use in a sed to remove the hostnames from rows that contain it. thoughts? here is some sample output:

Dev.us.corp.com 9.148.53.232 6A:8D:93:5E:1C:6E Unknown
QA2-Zpro.us.corp.com 9.148.53.235 00:14:5E:46:E7:B7 corp
Dev.us.corp.com 9.148.53.240 72:B5:01:E3:FE:D7 Unknown
files.us.corp.com 9.148.53.246 00:14:5E:1E:1F:80 corp
Dev.us.corp.com 9.148.53.247 22:DB:5C:22:AE:3C Unknown
source.us.corp.com 9.148.53.248 00:21:5E:F0:A3:39 corp
Dev.us.corp.com 9.148.53.249 22:F2:31:65:65:E4 Unknown
9.148.55.4 C8:4C:75:68:E3:42 Unknown
9.148.55.5
9.148.55.10 46:36:B9:18:8E:CB Unknown
9.148.55.15 96:7B:62:06:E0:B6 Unknown
9.148.55.16 00:16:41:37:43:AD USI
9.148.55.17 00:21:86:14:6C:4E USI
9.148.55.25 E4:1F:13:1F:16:CE Unknown

evo2 07-05-2012 02:32 AM

Hi,

instead of trying to parse the default output of nmap, have you considered using the various nmap options that modify the output format? Check the "OUTPUT:" section in the namp man page, or for more details see http://nmap.org/book/man-output.html

HTH,

Evo2.

gilad73 07-05-2012 03:27 AM

Thanks Evo2! I played around with some of the different out puts (in particular XML and converting to HTML), but that really provides more information than I need. Basically I just want the IP/Mac of up and running servers. I will use this file and join on another file to provide users with specific info they need for their machines.

Thanks!


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