The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to retain the header information of a file ahjiefreak UNIX for Dummies Questions & Answers 0 12-04-2007 07:21 PM
How to retain file permissions during FTP on Solaris 5.9 ? gauravsachan UNIX for Advanced & Expert Users 3 04-26-2007 10:19 AM
getting the most recent file anujairaj Shell Programming and Scripting 3 06-22-2006 03:34 PM
Changing name of most recent file warpmail AIX 1 02-15-2006 07:34 PM
Most Recent File script josborn777 Shell Programming and Scripting 1 03-29-2002 05:01 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-10-2007
CM64 CM64 is offline
Registered User
  
 

Join Date: Apr 2007
Posts: 13
parse an arpwatch file and retain most recent mac

Hi,

I'm working on a little script, for first I transformed epoch (unix date in seconds) in a human readable date in this way

cat arp.dat | sort -k 3 | gawk '{ print strftime("%d:%m:%Y:%H:%M", $3),$1,$2}'

the result is

06:03:2006:10:01 0:a:e4:c0:b5:6d 192.168.1.3
06:03:2006:12:15 0:a:e4:c0:b5:6e 192.168.1.4
......
07:03:2007:09:18 0:a:e4:c0:b5:6d 192.168.1.8

I am interested in parsing the arpwatch file and retaining just the more recent entries and produce another file, so I have to compare dates. How can I do?
  #2 (permalink)  
Old 04-10-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Code:
awk -F":" ' $3 == 2007 && $2 > 2 ' file >newfile
Add conditions according to your needs
  #3 (permalink)  
Old 04-10-2007
CM64 CM64 is offline
Registered User
  
 

Join Date: Apr 2007
Posts: 13
I don't understand very well where you say "add conditions according to your needs". The matter is a little more complicated, I've got about 2.000 entries, sometimes I've got something like this

01.01.2007:10.15 aa:bb:ecc. 1.2.3.4
01.01.2007:10.16 aa:bb:ecc. 1.2.3.5

(our lan is divided in pieces and uses DHCP, so a computer a laptop for example can have a complitely different ip in minutes)

so it's not pratical using == 2007(and eventually other statements) I think I need some kind of a function date/compare on date fild (as well hour) or maybe I miss something in your suggestion please give me details.
  #4 (permalink)  
Old 04-10-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Code:
awk ' { arr[$2]=$0 } 
END {
     for(key in arr) { print arr[key] }
}' file > newfile

Last edited by anbu23; 04-10-2007 at 08:15 AM..
  #5 (permalink)  
Old 04-10-2007
CM64 CM64 is offline
Registered User
  
 

Join Date: Apr 2007
Posts: 13
Thank you very much but I don't understand. I know is a fault of mine, I am a very beginning awk scripter. Can you give me a complete code, it' seems to me that is the key statement that is the "key" but I don't understand how to use it.
  #6 (permalink)  
Old 04-10-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Code:
$ cat file
06:03:2006:10:01 0:a:e4:c0:b5:6d 192.168.1.3
06:03:2006:12:15 0:a:e4:c0:b5:6e 192.168.1.4
07:03:2007:09:18 0:a:e4:c0:b5:6d 192.168.1.8
01.01.2007:10.15 aa:bb:ecc. 1.2.3.4
01.01.2007:10.16 aa:bb:ecc. 1.2.3.5
$ awk ' { arr[$2]=$0 }
> END {
>      for(key in arr) { print arr[key] }
> }' file
07:03:2007:09:18 0:a:e4:c0:b5:6d 192.168.1.8
06:03:2006:12:15 0:a:e4:c0:b5:6e 192.168.1.4
01.01.2007:10.16 aa:bb:ecc. 1.2.3.5
If this is not the expected output, can you show sample input and output?
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:43 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0