compare text in log file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting compare text in log file
# 1  
Old 10-13-2011
compare text in log file

Hi all,

I am posting the thread similar to previous posts but here my scenario is i need to know what the files size from start date. Here end time file size will be 0. Also need to know how much time does it took to complete in seconds.

log file:

Name1 START 11:36:45 13102011 File: 2015443 size: 187654 File: 0 size: 0

Name1 END 11:38:47 13102011 File: 0 size: 0 File: 0 size: 0

Name2 START 11:39:52 13102011 File: 2008395 size: 28764 File: 0 size: 0

Name2 END 11:40:21 13102011 File: 0 size: 0 File: 0 size: 0

Name1 START 11:41:59 13102011 File: 1056987 size: 467321 File: 0 size: 0

Name1 END 11:42:36 13102011 File: 0 size: 0 File: 0 size: 0

the result should be

Name1 END ENDTIME time_diff_seconds date File: 2015443 size: 187654 File: 0 size: 0

Name2 END ENDTIME time_diff_Seconds date File: 2008395 size: 28764 File: 0 size: 0

Name3 END ENDTIME time-diff_seconds date File: 1056987 size: 467321 File: 0 size: 0

Can any one please me out.

Regards
Olivia
# 2  
Old 10-13-2011
I saw four Name1 , typo?

---------- Post updated at 10:32 AM ---------- Previous update was at 10:22 AM ----------

Code:
awk 'function time(r,s,t,x,y,z) 
      {str1=mktime("2011 1 1" FS r FS s FS t)
       str2=mktime("2011 1 1" FS x FS y FS z)
       diff=str1-str2 
       H=int(diff/3600)
       M=int((diff-H*3600)/60)
       S=diff-H*3600-M*60
       return sprintf ("%02d:%02d:%02d",H,M,S) 
      }
      /START/ {a[$1]=$3;file[$1]=$6;size[$1]=$8}
      /END/&&a[$1] { split(a[$1],b,":") 
                          split($3,c,":") 
                          c[1]=c[1]>=b[1]?c[1]:c[1]+24
                          printf "%-6s END %s %s %s File: %s size: %s File: 0 size: 0 \n", $1, $3,time(c[1],c[2],c[3],b[1],b[2],b[3]),$4,file[$1],size[$1]
                          delete a[$1]
                        }' sample.TXT

Name1  END 11:38:47 00:02:02 13102011 File: 2015443 size: 187654 File: 0 size: 0
Name2  END 11:40:21 00:00:29 13102011 File: 2008395 size: 28764 File: 0 size: 0
Name3  END 11:42:36 00:00:37 13102011 File: 1056987 size: 467321 File: 0 size: 0

# 3  
Old 10-13-2011
Thank you so much, no there was a typo in result actually it should be name1 (The same jobs would be running repeatedly as per predefined jobs other scripts) also can you suggest me how to rewrite so that i can get only in seconds rather HH:MM:SS i.e 120seconds if it is 00:02:00.

Quote:
Originally Posted by rdcwayx
I saw four Name1 , typo?

---------- Post updated at 10:32 AM ---------- Previous update was at 10:22 AM ----------

Code:
awk 'function time(r,s,t,x,y,z) 
      {str1=mktime("2011 1 1" FS r FS s FS t)
       str2=mktime("2011 1 1" FS x FS y FS z)
       diff=str1-str2 
       H=int(diff/3600)
       M=int((diff-H*3600)/60)
       S=diff-H*3600-M*60
       return sprintf ("%02d:%02d:%02d",H,M,S) 
      }
      /START/ {a[$1]=$3;file[$1]=$6;size[$1]=$8}
      /END/&&a[$1] { split(a[$1],b,":") 
                          split($3,c,":") 
                          c[1]=c[1]>=b[1]?c[1]:c[1]+24
                          printf "%-6s END %s %s %s File: %s size: %s File: 0 size: 0 \n", $1, $3,time(c[1],c[2],c[3],b[1],b[2],b[3]),$4,file[$1],size[$1]
                          delete a[$1]
                        }' sample.TXT

Name1  END 11:38:47 00:02:02 13102011 File: 2015443 size: 187654 File: 0 size: 0
Name2  END 11:40:21 00:00:29 13102011 File: 2008395 size: 28764 File: 0 size: 0
Name3  END 11:42:36 00:00:37 13102011 File: 1056987 size: 467321 File: 0 size: 0

# 4  
Old 10-13-2011
It will be more simple.
Code:
awk 'function time(r,s,t,x,y,z) 
      {str1=mktime("2011 1 1" FS r FS s FS t)
       str2=mktime("2011 1 1" FS x FS y FS z)
       return str1-str2   
      }
      /START/ {a[$1]=$3;file[$1]=$6;size[$1]=$8}
      /END/&&a[$1] { split(a[$1],b,":") 
                          split($3,c,":") 
                          c[1]=c[1]>=b[1]?c[1]:c[1]+24
                          printf "%-6s END %s %s second(s) %s File: %s size: %s File: 0 size: 0 \n", $1, $3,time(c[1],c[2],c[3],b[1],b[2],b[3]),$4,file[$1],size[$1]
                          delete a[$1]
                        }' sample.TXT

# 5  
Old 10-13-2011
SunOS 5.10 Generic_142900-15 sun4v sparc SUNW,T5240

how can i check the storage type being used in unix solaris sparc system?
please help me its urgnet..

thank you
# 6  
Old 10-14-2011
Thank you so much. So grateful for your help.

Quote:
Originally Posted by rdcwayx
It will be more simple.
Code:
awk 'function time(r,s,t,x,y,z) 
      {str1=mktime("2011 1 1" FS r FS s FS t)
       str2=mktime("2011 1 1" FS x FS y FS z)
       return str1-str2   
      }
      /START/ {a[$1]=$3;file[$1]=$6;size[$1]=$8}
      /END/&&a[$1] { split(a[$1],b,":") 
                          split($3,c,":") 
                          c[1]=c[1]>=b[1]?c[1]:c[1]+24
                          printf "%-6s END %s %s second(s) %s File: %s size: %s File: 0 size: 0 \n", $1, $3,time(c[1],c[2],c[3],b[1],b[2],b[3]),$4,file[$1],size[$1]
                          delete a[$1]
                        }' sample.TXT

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare Values in a Delimited Text file

Hi, How do I compare two columns within a text file If 2nd column values are same then I want to know 3rd column number matches or not Example: Prod Stag1 1234.79 Prod Stag2 1234.79 20 Prod Stag3 1234.79 30 Prod Stag4 1234.79 UAT Stag1 1243.56 UAT Stag2 1243.56 20 UAT ... (3 Replies)
Discussion started by: krux_rap
3 Replies

2. Shell Programming and Scripting

Compare output of UNIX command and match data to text file

I am working on an outage script and I run a command from the command line which tells me the amount of generator failures in my market. The output of this command only gives me three digits to identify the site by. I have a master list of all sites in a separate file, call it list.txt. If my... (7 Replies)
Discussion started by: jbrass
7 Replies

3. Shell Programming and Scripting

Compare 2 text file with 1 column in each file and write mismatch data to 3rd file

Hi, I need to compare 2 text files with around 60000 rows and 1 column. I need to compare these and write the mismatch data to 3rd file. File1 - file2 = file3 wc -l file1.txt 58112 wc -l file2.txt 55260 head -5 file1.txt 101214200123 101214700300 101250030067 101214100500... (10 Replies)
Discussion started by: Divya Nochiyil
10 Replies

4. Shell Programming and Scripting

Compare the text/integer value from the log file

i have some log (temp.txt) file like temp.txt: Filesystem size used avail capacity Mounted on /dev/md/dsk/d30 9.8G 9.7G 14M 100% /opt /dev/md/dsk/d72 187M 61M 107M 37% /osmf/mgmt /dev/md/dsk/d71 187M 140M 29M 83% /export/home /dev/md/dsk/d70 7.9G 4.3G 3.5G 56% /var/crash /dev/md/dsk/d74... (6 Replies)
Discussion started by: doubt
6 Replies

5. Shell Programming and Scripting

Compare text file and a folder

Hi, I have a folder which contains some files a1.txt a2.txt a3.txt a4.txt a5.txt a6.txt a7.txt a8.txt a_index.txt Also i have a text file which contains entries like this a1.txt a3.txt a7.txt I want to comapare this text file and folder and remove the similar values in... (12 Replies)
Discussion started by: arijitsaha
12 Replies

6. Shell Programming and Scripting

Compare two text file and output the same to third file

Need help. I have a source file that listed sets of numbers/words and what i'm trying to do is, by each line of the source file i want to look for same numbers/words in second file and if it match then write it to third file. Third file should have whole line from source file plus whole line... (7 Replies)
Discussion started by: suresh7730
7 Replies

7. UNIX for Dummies Questions & Answers

Compare and merging the differences in text file

Hi i have gone through some sdiff command it shows the differences side by side and its really awesome file 1: this tool is for checking the differ merging with flower pots documentation file 2: this t ool is for checking the differ mergin g with flower pots documentation ... (27 Replies)
Discussion started by: rakeshkumar
27 Replies

8. UNIX for Dummies Questions & Answers

SOLVED: Text file compare using perl

I have two text file.... One text file contain in this format...... keyvalue.txt \SUM\SUM_cam.c \SUM\SUM_cam.h \SUM\SUM_command.c \SUM\SUM_command.h \SUM\SUM_dab.c \SUM\SUM_dmb.c \SUM\SUM_eventHandler.h \SUM\SUM_eventHandler_dab.c \SUM\SUM_eventHandler_dmb.c ... (6 Replies)
Discussion started by: suvenduperl
6 Replies

9. Shell Programming and Scripting

variable getting results from a log file; compare it in an IF cycle

Hi All I am going crazy trying to resolve this easy task.... I have a log file that is created by xcode; and it contains the results of a build (either success or fail); what i am trying to achieve here is to get the result from the log, and check if is a pass or fail in an IF statement, so... (3 Replies)
Discussion started by: newbiez
3 Replies

10. Shell Programming and Scripting

Log File date compare for user defined range

:confused: Hi i am a noob and need a little help to finish my shell script. I am learning as i go but hit a problem. I am search thorugh logs(*.rv) files to find entires between two user defined dates, The script so far looks for the "START" and "END" of each entry at sees if it belongs To... (0 Replies)
Discussion started by: mojo24
0 Replies
Login or Register to Ask a Question