![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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 FINAL TEXT FILE Code:
00.11.50.d7.c7.3c 00.03.93.ec.21.93 00.19.e8.d8.c2.e0 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 |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
[code:]
nawk -F'[()]' 'NR>3 {print $4}' filename [code:] |
|
#3
|
|||
|
|||
|
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. |
|
#4
|
||||
|
||||
|
set the field seperators as "(" or ")" :
Code:
-F'[()]' Code:
'NR>3 Code:
{print $4}'
Last edited by Tytalus; 01-24-2008 at 06:20 AM. Reason: ninor typos |
|
#5
|
|||
|
|||
|
Brilliant, thanks for that. Very helpful.
|
|
#6
|
|||
|
|||
|
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
|
|
#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
Comments welcome. |
|||
| Google The UNIX and Linux Forums |