parse an arpwatch file and retain most recent mac


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting parse an arpwatch file and retain most recent mac
# 1  
Old 04-10-2007
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  
Old 04-10-2007
Code:
awk -F":" ' $3 == 2007 && $2 > 2 ' file >newfile

Add conditions according to your needs
# 3  
Old 04-10-2007
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  
Old 04-10-2007
Code:
awk ' { arr[$2]=$0 } 
END {
     for(key in arr) { print arr[key] }
}' file > newfile


Last edited by anbu23; 04-10-2007 at 09:15 AM..
# 5  
Old 04-10-2007
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  
Old 04-10-2007
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?
# 7  
Old 04-11-2007
Ok. Input file

date mac ip
01:01:01:10.01 aa:bb:cc:dd:ee:ff 1.2.3.4
01:01:01:10.02 aa:bb:cc:dd:ee:ff 1.2.3.3
01:01:01:10.03 aa:bb:cc:dd:ee:ff 1.2.3.5
01:01:01:10.04 aa:bb:cc:dd:ee:ff 1.2.3.8
....
05:01:01:10.01 aa:bb:cc:dd:ee:00 1.2.3.9

I want this output file
01:01:01:10.04 aa:bb:cc:dd:ee:ff 1.2.3.8
05:01:01:10.01 aa:bb:cc:dd:ee:00 1.2.3.9

I can have hundreds of entries in the input file, some have just one triplet (date mac ip) and I want this rows to be reported, some have many triplets where there is only one identical element the mac, data and ip are different in this case I want only the most recent row and the others supressed.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

cat to a file but retain header

Hi, Is there a way to write to a txt file each day but retain the header on the file? I'm cat'ing 5 files into one .txt file each day but I want the new data to be written after the first 2 lines which are: Progname Size Date Owner ---------------------------- Basically I want my new... (4 Replies)
Discussion started by: Grueben
4 Replies

2. Shell Programming and Scripting

How to retain backslash in a line while reading a data file?

Hello Firends I have a file that contains data within single quotes, which has meaning of its own. When I am trying to parse through the file for a different functionality I noticed that I was loosing the backslash when occurrences in the file look like ('\0'). I would want to retain the... (3 Replies)
Discussion started by: easwam
3 Replies

3. Shell Programming and Scripting

retain last 1000 line in a file

I have large file with around 100k+ lines. I wanted to retain only the last 100 lines in that file. One way i thought was using tail -1000 filename > filename1 mv filename1 filename But there should be a better solution.. Is there a way I can use sed or any such command to change the... (9 Replies)
Discussion started by: nss280
9 Replies

4. Shell Programming and Scripting

Retain File Timestamp

There are directories of files that I have to run the dos2ux command on to get ride of the carriage return characters. Easy enough, but I have to retain the original timestamps on the files. I am thinking that I am going to have to strip off the timestamp for each file and convert it to unix time... (3 Replies)
Discussion started by: scotbuff
3 Replies

5. UNIX for Advanced & Expert Users

Retain Only specific number of file in Directory

I want to retain specific number of backup files in a directory.for example i want to retain only two latest backup file in backup directory. If number of backup files is greater than this policy that it will delete oldest file.Please Tell me whether this is possible or not. (2 Replies)
Discussion started by: ranvijaidba
2 Replies

6. Shell Programming and Scripting

Retain file permissions when saving .sh file from internet [OS X]

Hello. I have written a bash script that I am sharing with an OS X community I am a member of. The purpose of the script is to execute a series of commands for members without them having to get involved with Terminal, as it can be daunting for those with no experience of it at all. I have renamed... (4 Replies)
Discussion started by: baza210
4 Replies

7. UNIX for Dummies Questions & Answers

How to retain the header information of a file

Hi, I am using Bash shell to create some data and these data would be piped out to a file, let say output.txt. This output.txt I would like to add some extra header information such as comments, descriptions and general information on the text. I would like to know how could I maintain... (0 Replies)
Discussion started by: ahjiefreak
0 Replies

8. UNIX for Advanced & Expert Users

How to retain file permissions during FTP on Solaris 5.9 ?

Hi All, I am trying to ftp a file : -rw-rw-rw- 1 oraclepbdw dba filename.txt from Machine A ( where umask is 022) to Machine B (umask 022) but the file changes to -rw-rw-r-- 1 ftpamle3 ftaml filename.txt Dur some constraints the group of the users on either side... (3 Replies)
Discussion started by: gauravsachan
3 Replies

9. Shell Programming and Scripting

getting the most recent file

Hi, I have files coming in every day with that days timestamp like: nameyyyymmddhhmmss.ext. I need the most recent one and so i am using cat `ls -t name*|head -1 ` > temp i am sorting the files in the decending order and am copying the most recent one into a temp file. It works at times... (3 Replies)
Discussion started by: anujairaj
3 Replies

10. Cybersecurity

arpwatch!

I want to configure arpwatch for ip-level security for some of the machine on the network. network is 10.129.112.0/25 but i want to look at those arp request which has ip from 10.129.112.160-179 and only(these machines) arpwatch -n 10.129.112.160/27 -d will give lot of entries... (0 Replies)
Discussion started by: yogesh_powar
0 Replies
Login or Register to Ask a Question