Awk find and sel


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk find and sel
# 1  
Old 04-03-2010
Awk find and sel

Hi to all!

I need to make an script to find when an user changes the IP. The log file have this simple structure;

example.txt
Code:
Jack 192.168.1.2
Tom 192.168.12.225
Mary 192.168.1.22
Jack 192.168.1.5
Patrick 192.168.1.88

If match the same user in the first column and have differents IP in the second then... ALERT!!

Thanks to all people who can help me!

Bye!
# 2  
Old 04-03-2010
you can use "-mtime" to understand if a file is modified or not. Or if you are looking for a detailed awk solution then you can copy the original file and then compare it with original one in some periods, for example copy your file as sample.txt then compare it with original one:

Code:
awk '{getline x < "sample.txt"
       split(x,a," ")
       for(i=1;i<=NF;i++)
       {if(a[i] != $i)
       {printf"%-s %-s %-s\n","line="NR,"column="i,"CHANGED"}}
        }' infile

# 3  
Old 04-03-2010
Code:
awk '{if(a[$1] && a[$1]!=$2){print "WARNING: IP of "$1" has changed from " a[$1]" to "$NF;a[$1]=$NF}else{a[$1]=$NF}}'log.file

Is that what you want ?

Quote:
I need to make an script to find when an user changes the IP.
I don't see a time-stamp in your log.

Last edited by danmero; 04-04-2010 at 04:39 AM.. Reason: Fix mistake, my bad ;)
# 4  
Old 04-04-2010
Code:
#!/bin/bash
sort -k 1.1,1 sample.txt | while read N2 IP2
do
    if [ "$N2" = "$N1" ] && [ "$IP2" != "$IP1" ]
    then
        echo "WARNING: IP of $N2 has changed from $IP1 to $IP2"
    fi
    N1="$N2"; IP1="$IP2"
done

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find and replace in awk

I have a file that I am trying to find a specific word, then replace text within that string. file TestA2015 TestB2016 Example. Replace TestB2016 to TestB0000, so if TestB is found replace the original "2016" to "0000". Thank you :). awk tried awk '{ sub(/TestB$/, "0000", $6) }1'... (5 Replies)
Discussion started by: cmccabe
5 Replies

2. Shell Programming and Scripting

awk to find the max

Experts, Here is my question. I have got file like below # cat file XYZb,24,26,6 XYZc,24,26,6 XYZe,24,25,5 XYZf,23,29,5 XYZi,16,25,5 XYZj,24,26,7 XYZn,17,23,4 XYZz,23,29,5 Now, I want to print the line's Column1 whose Column 3 is the max of all. My code is awk -F',' 'BEGIN {max... (9 Replies)
Discussion started by: sathyaonnuix
9 Replies

3. Shell Programming and Scripting

awk conditional find

Hi, I have a file in the following format: aabbba 25.31806899 baaabb 38.21808852 cccccu 1.31819523 552258121.31818253 ffddybb 5.41815555 almcamc87561812689 223aqas5.661828345 adacaaaaaaa1821285 adacaaaaaaa1821286 smckaa 3.81828756 ada2512510c1821287 ada2522511c1821328... (4 Replies)
Discussion started by: alex2005
4 Replies

4. Shell Programming and Scripting

Using awk to find sentences.

I am trying to print out sentences that meets a regular expression in awk (I’m open to using other tools, too). I got the regular expression I want to use, "(\+ \{4\})" from user ripat in a grep forum. Unfortunately with grep I couldn't print only the sentence. While searching for awk... (8 Replies)
Discussion started by: danbroz
8 Replies

5. Shell Programming and Scripting

Help with find, xargs and awk

Hi, I want to find some files and then search for some lines in it with a particular pattern and then write those lines into a file. To do this I am using something like this from command prompt directly. cd /mdat/BVG find -name "stmt.*cl" -newer temp.txt | xargs -i awk '/BVG-/{print}' {} >... (7 Replies)
Discussion started by: Sandhya Harsh
7 Replies

6. UNIX for Dummies Questions & Answers

Is there a Cron instal pkg for MIPS-SEL processors?

Does anyone know if there is a pkg for installing cron on a mips processor machine with embedded linux? (0 Replies)
Discussion started by: Trogman
0 Replies

7. Shell Programming and Scripting

Need to find the greates value using AWK.

Friends, I have to find out the greatest amoings three values using awk. Actually i have to run the iostat -d command on my linux box for 5 or 6 iterations and print the largest value for tps at each iteration for e.g iostat -d 3 3 Linux 2.6.18-8.el5 (abhijit) 11/19/2009 _i686_ (2... (8 Replies)
Discussion started by: achak01
8 Replies

8. UNIX for Dummies Questions & Answers

grep, find or awk?

Since I found this very helpful forum and friendly people, I have a small request. I use AIX Unix and would like to know if there's a simple way how to do a kind of compare between two files. Should I use some grep, find or awk? I have 2 text files, let's name them file1 and file2. What I... (4 Replies)
Discussion started by: netrom
4 Replies
Login or Register to Ask a Question