LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


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

Rep: Reputation: Disabled
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:FE7 Unknown
files.us.corp.com 9.148.53.246 00:14:5E:1E:1F:80 corp
Dev.us.corp.com 9.148.53.247 22B: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
 
Old 07-05-2012, 02:32 AM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
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.
 
Old 07-05-2012, 03:27 AM   #3
gilad73
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.

Thanks!
 
  


Reply

Tags
regex, sed



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 05:19 AM
How to remove a value with sed mierdatuti Programming 3 12-18-2008 05:36 PM
using sed to remove all but ip addresses chess Programming 10 07-02-2007 01:54 AM
help with sed to remove all text except for some Benanzo Linux - Software 7 01-04-2007 06:21 AM
Remove string in sed twantrd Programming 7 09-13-2006 02:28 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:08 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration