The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Using Mailx to send to list of email addresses aguad3 UNIX Desktop for Dummies Questions & Answers 1 03-28-2008 12:40 PM
memory addresses Paravozzz High Level Programming 0 10-15-2002 09:17 AM
Extracting String from a list odogbolu98 Shell Programming and Scripting 4 05-31-2002 11:48 PM
Ip Addresses evil_d00d IP Networking 4 02-27-2002 12:32 AM
ip addresses dragonslayer100 IP Networking 2 01-28-2002 05:25 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 01-24-2008
Registered User
 

Join Date: Jan 2008
Posts: 7
Help extracting MAC addresses from List

Hello all.

I have a large number of text files outputted from various Netstumbler Wireless Scans; from which I need to extract the MAC addresses of the various Access Points.

The Text files look like this:

Code:
# $Creator: Network Stumbler Version 0.4.0
# $Format: wi-scan summary with extensions
# Latitude	Longitude	( SSID )	Type	( BSSID )	Time (GMT)	[ SNR Sig Noise ]	# ( Name )	Flags	Channelbits	BcnIntvl	DataRate	LastChannel
# $DateGMT: 2008-01-16
N 0.0000000	E 0.0000000	( belkin54g )	BSS	( 00:11:50:d7:c7:3c )	16:44:39 (GMT)	[ 19 68 49 ]	# (  )	0411	00000800	100	540	11
N 0.0000000	E 0.0000000	( BUFVC Wireless )	BSS	( 00:03:93:ec:21:93 )	16:44:39 (GMT)	[ 33 82 49 ]	# (  )	0411	00000080	100	540	7
N 0.0000000	E 0.0000000	( F-Wireless Zone )	BSS	( 00:19:e8:d8:c2:e0 )	16:44:39 (GMT)	[ 24 73 49 ]	# (  )	0421	00002000	100	540	13
What I would like to do is extract the MAC addresses into another text file so that it ends up looking like this:

FINAL TEXT FILE
Code:
00.11.50.d7.c7.3c
00.03.93.ec.21.93
00.19.e8.d8.c2.e0
I'm pretty new at this whole scripting thing, but I've managed to work our a couple of steps of this process.

1) I can use grep 'N 0.0' to get just the lines with MAC addresses

2) I can probably use tr -d to delete the () around the MAC addresses

What I'm failing to be able to do is basically everything else

1) how do I get just the MAC addresses out of that long line?
2) how do I swap the ":" separating the parts of the MAC addresses for "." ?

I realise this is probably fairly straight forward, and I've tried looking in the various man pages for the likes of awk, sed and grep, but to be honest they are a little confusing.

Any help getting my Wireless Scan text file to look like my hoped for Final text file would be greatly appreciated!

Cheers
Reply With Quote
Forum Sponsor
  #2  
Old 01-24-2008
Registered User
 

Join Date: Jan 2008
Posts: 52
[code:]


nawk -F'[()]' 'NR>3 {print $4}' filename


[code:]
Reply With Quote
  #3  
Old 01-24-2008
Registered User
 

Join Date: Jan 2008
Posts: 7
Thanks!

Initially it didn't work, and returned "command not found" but after a little research I realised that nawk is just "new awk" so subtituted awk, and it worked. (I don't think OS X has nawk installed)

Thank you very much.

Secondary question, if you have time, could you explain how it's working...

What are the various parts of that command doing? It would help me in the future to understand what is going on.

Cheers.
Reply With Quote
  #4  
Old 01-24-2008
Tytalus's Avatar
Registered User
 

Join Date: Jun 2003
Location: Scotland
Posts: 286
set the field seperators as "(" or ")" :
Code:
-F'[()]'
Then for any record (aka line) number >3 :
Code:
 'NR>3
print the 4th field :
Code:
{print $4}'

Last edited by Tytalus; 01-24-2008 at 06:20 AM. Reason: ninor typos
Reply With Quote
  #5  
Old 01-24-2008
Registered User
 

Join Date: Jan 2008
Posts: 7
Brilliant, thanks for that. Very helpful.
Reply With Quote
  #6  
Old 01-29-2008
Registered User
 

Join Date: May 2007
Posts: 104
Not quite as neat or clean as the awk example, but perhaps useful if the field changes:
Code:
egrep -o "[a-z0-9]{2}:[a-z0-9]{2}:[a-z0-9]{2}:[a-z0-9]{2}:[a-z0-9]{2}:[a-z0-9]{2}" filename
Reply With Quote
  #7  
Old 01-29-2008
Registered User
 

Join Date: Jan 2008
Posts: 7
Interesting. I really like that way of doing it actually. And as you say, could be useful if NetStumbler changes their output format.

If anyone is interested, here is the finished script.
Code:
#!/bin/sh

# This script combines the Netstumbler wireless reports and trims and formats them for the monthly report.
# It needs to be run from the directory in which the text files are stored.
# There should NOT be any other files in the directory, and they should all have the file extension .txt

# Combines the files into one

cat *.txt > all0.txt

# Trims out only relevant lines

grep 'N 0.0' all0.txt > all1.txt

# Trims out the rubbish, and outputs the MACS only

awk -F'[()]' 'NR {print $4}' all1.txt > all2.txt

# Substitutes "." for ":" as the MAC address separators

sed -e 's/:/./g' all2.txt > MAC_addresses_from_wireless_scan.txt

# Removes the leftover text files.

rm all0.txt
rm all1.txt
rm all2.txt
I'm sure there is a neater way to do it, without the intermediate files, but as I'm fairly new at this scripting, and just wanted the job done, I went with the way I was sure I could do it.

Comments welcome.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:13 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0