Quantcast
Channel: UNIX and Linux Forums
Viewing all articles
Browse latest Browse all 16232

how awk compare output from 'last -x' with file

$
0
0
Hi awk masters,

I need help how to compare output from 'last -x' (command cli from linux) with the file1.txt. if output from last -x is there new entry, then awk write the different in the file2.txt.

example:
result output from " last -x |grep 'shutdown\|reboot' " :
Code:

[root@localhost awk]# last -x |grep 'shutdown\|reboot'
reboot  system boot  2.6.18-194.el5  Mon Jul 16 19:26          (00:09)   
shutdown system down  2.6.18-194.el5  Mon Jul 16 03:36 - 19:36  (16:00)   
reboot  system boot  2.6.18-194.el5  Sun Jul 15 20:46          (06:48)   

shutdown system down  2.6.18-194.el5  Fri Jul 13 03:59 - 03:35 (2+23:36) 
reboot  system boot  2.6.18-194.el5  Fri Jul 13 03:32          (00:26)   
shutdown system down  2.6.18-194.el5  Fri Jul 13 03:29 - 03:59  (00:29)   
reboot  system boot  2.6.18-194.el5  Fri Jul 13 00:01          (03:27)   
shutdown system down  2.6.18-194.el5  Thu Jul 12 23:59 - 03:29  (03:29)   
reboot  system boot  2.6.18-194.el5  Thu Jul 12 23:33          (00:26)   
shutdown system down  2.6.18-194.el5  Thu Jul 12 23:31 - 23:59  (00:28)   
reboot  system boot  2.6.18-194.el5  Fri Jul 13 04:35          (-5:-3)

the file1.txt :
Code:

[root@localhost awk]# cat file1.txt
shutdown system down  2.6.18-194.el5  Fri Jul 13 03:59 - 23:28 (2+19:28) 
reboot  system boot  2.6.18-194.el5  Fri Jul 13 03:32          (00:26)   
shutdown system down  2.6.18-194.el5  Fri Jul 13 03:29 - 03:59  (00:29)   
reboot  system boot  2.6.18-194.el5  Fri Jul 13 00:01          (03:27)   
shutdown system down  2.6.18-194.el5  Thu Jul 12 23:59 - 03:29  (03:29)   
reboot  system boot  2.6.18-194.el5  Thu Jul 12 23:33          (00:26)   
shutdown system down  2.6.18-194.el5  Thu Jul 12 23:31 - 23:59  (00:28)   
reboot  system boot  2.6.18-194.el5  Fri Jul 13 04:35          (-5:-3)

and the final output needed in the file2.txt :
Code:

reboot  system boot  2.6.18-194.el5  Mon Jul 16 19:26          (00:09)   
shutdown system down  2.6.18-194.el5  Mon Jul 16 03:36 - 19:36  (16:00)   
reboot  system boot  2.6.18-194.el5  Sun Jul 15 20:46          (06:48)

and if the file2.txt has been updated, the file1.txt must have/update all entry. like this :
Code:

reboot  system boot  2.6.18-194.el5  Mon Jul 16 19:26          (00:09)   
shutdown system down  2.6.18-194.el5  Mon Jul 16 03:36 - 19:36  (16:00)   
reboot  system boot  2.6.18-194.el5  Sun Jul 15 20:46          (06:48)   
shutdown system down  2.6.18-194.el5  Fri Jul 13 03:59 - 03:35 (2+23:36) 
reboot  system boot  2.6.18-194.el5  Fri Jul 13 03:32          (00:26)   
shutdown system down  2.6.18-194.el5  Fri Jul 13 03:29 - 03:59  (00:29)   
reboot  system boot  2.6.18-194.el5  Fri Jul 13 00:01          (03:27)   
shutdown system down  2.6.18-194.el5  Thu Jul 12 23:59 - 03:29  (03:29)   
reboot  system boot  2.6.18-194.el5  Thu Jul 12 23:33          (00:26)   
shutdown system down  2.6.18-194.el5  Thu Jul 12 23:31 - 23:59  (00:28)   
reboot  system boot  2.6.18-194.el5  Fri Jul 13 04:35          (-5:-3)

im very appreciate if all my brother in this forum to help me out.
thanks very much.

Viewing all articles
Browse latest Browse all 16232

Trending Articles