Linux Help
guides forums blogs
Home Desktops Distributions ISO Images Logos Newbies Reviews Software Support & Resources Linuxhelp Wiki

Welcome Guest ( Log In | Register )



Advanced DNS Management
New ZoneEdit. New Managment.

FREE DNS Is Back

Sign Up Now
 
Reply to this topicStart new topic
> A fairly noobish AWK question
DKF295
post May 17 2009, 09:38 PM
Post #1


Whats this Lie-nix Thing?
*

Group: Members
Posts: 1
Joined: 17-May 09
Member No.: 14,459



QUOTE
Figured it out, figured I'd post the solution before closing the thread.

awk ' if (substr($1,1,8) == "00:0A:80") printf("\n%s", $1);else printf(" %s", $1) file.txt


Introduction: I'll be upfront and say that I'm quite the noob when it comes to programming outside of my comfort zone, which is VB. I very much believe in the idea that a man is best served by being taught how to fish, I'm mostly just looking to much, much better fishermen to tell me if I'm using the right reel, rod, and bait. My primary question is if AWK is really my best bet to accomplish what I want to accomplish. Secondary help that would be appreciated but are absolutely not necessary include suggested tutorials (already went through the bulk of http://www.vectorsite.net/tsawk.html for awk), providing general thoughts to ponder in regards to overall script structure, etc.

The problem: Basically, I have a combination shell/expect script (running on a really scaled-down Debian platform) in which the shell script launches the expect script, which logs into a device via telnet that for all intents and purposes can be considered a router. It then grabs a huge list of MAC addresses and other assorted information from said router, saves it to disk, logs out, and the script terminates.

Meanwhile, the shell script cleans out the output, returning just the MAC addresses, line by line. Here is an example of a portion of the output at this point, in the form of a file:

CODE
00:0A:80:21:00:08
00:21:9B:CB:C1:19
00:0A:80:21:00:44
00:0A:80:21:01:52
00:23:8B:3A:81:78
00:1C:25:9C:42:01
00:0A:80:21:03:9E
00:17:F2:D1:B9:36
00:0A:80:21:03:D4
00:23:5A:2D:72:7D


At this point, I wish the final output to resemble the following:

CODE
00:0A:80:21:00:08 00:21:9B:CB:C1:19
00:0A:80:21:00:44
00:0A:80:21:01:52 00:23:8B:3A:81:78 00:1C:25:9C:42:01
00:0A:80:21:03:9E 00:17:F2:D1:B9:36
00:0A:80:21:03:D4 00:23:5A:2D:72:7D


Context: All devices starting with MAC 00:0A:80 are a parent device of zero or more other devices. All the other MACs are random devices attached to this device. So in the above example, 00:0A:80:21:00:44 has nothing plugged into it, 00:0A:80:21:01:52 has two devices plugged into it (00:23:8B:3A:81:78, 00:1C:25:9C:42:01). Each line should start with the 00:0A:80 device's MAC, all attached devices's MACs should follow, separated by spaces.

Is AWK even my best bet here? I've done some minor poking around/tutorial reading with sed, but I don't think that it is my answer... Thoughts, suggestions, etc? If AWK is my best bet, is thinking about implementing arrays productive or counterproductive?
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 25th November 2017 - 06:38 AM