LinuxAnswers - the LQ Linux tutorial section.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 07-05-2012, 03:24 AM   #1
LQ Newbie
Registered: Jun 2012
Posts: 8

Rep: Reputation: Disabled
remove hostname using sed

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: 6A:8D:93:5E:1C:6E Unknown 00:14:5E:46:E7:B7 corp 72:B5:01:E3:FE7 Unknown 00:14:5E:1E:1F:80 corp 22B:5C:22:AE:3C Unknown 00:21:5E:F0:A3:39 corp 22:F2:31:65:65:E4 Unknown C8:4C:75:68:E3:42 Unknown 46:36:B9:18:8E:CB Unknown 96:7B:62:06:E0:B6 Unknown 00:16:41:37:43:AD USI 00:21:86:14:6C:4E USI E4:1F:13:1F:16:CE Unknown
Old 07-05-2012, 03:32 AM   #2
LQ Guru
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1286Reputation: 1286Reputation: 1286Reputation: 1286Reputation: 1286Reputation: 1286Reputation: 1286Reputation: 1286Reputation: 1286

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


Old 07-05-2012, 04:27 AM   #3
LQ Newbie
Registered: Jun 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
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.



regex, sed

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to remove using sed vixxant Linux - Newbie 3 05-24-2012 06:19 AM
How to remove a value with sed mierdatuti Programming 3 12-18-2008 06:36 PM
using sed to remove all but ip addresses chess Programming 10 07-02-2007 02:54 AM
help with sed to remove all text except for some Benanzo Linux - Software 7 01-04-2007 07:21 AM
Remove string in sed twantrd Programming 7 09-13-2006 03:28 PM

All times are GMT -5. The time now is 10:38 PM.

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