Home Man
Search
Today's Posts
Register

The Solaris Operating System, usually known simply as Solaris, is a Unix-based operating system introduced by Sun Microsystems. The Solaris OS is now owned by Oracle.

Find highest value of a particular property in multiple files

Tags
solaris

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 09-28-2017
Find highest value of a particular property in multiple files

I have multiple files with pattern of "*.tps (example:tps-20170307170421560-1053.tps)" in my log directory(files are in different sub directories).

entries in files are given below. I want to extract highest value of endtime accross all files.

Code:
"endTime :1488902691462"

Code:
{"endTime":1488902691462,"startTime":1488902691462,"operationIdentity":"publishCacheStatistics","name":"murex.limits.utilities.cache.statistics.CacheStatisticsTimerTask","context":{"parentContext":{"id":-1,"parentContext":null},"data":[{"value":"GlobalRuleCache:Util_Algos_Ctp_Notional_Bar:ValidationRuleRepository","key":"name"},{"value":"0","key":"hits"},{"value":"0","key":"misses"},{"value":"0","key":"count"},{"value":"0","key":"maxElements"},{"value":"0","key":"evictions"},{"value":"Default","key":"policy"}],"id":0}}
{"endTime":1488902691471,"startTime":1488902691471,"operationIdentity":"publishCacheStatistics","name":"murex.limits.utilities.cache.statistics.CacheStatisticsTimerTask","context":{"parentContext":{"id":-1,"parentContext":null},"data":[{"value":"GlobalRuleCache:Diff_Bar_No_Engine:ValidationRuleRepository","key":"name"},{"value":"0","key":"hits"},{"value":"0","key":"misses"},{"value":"0","key":"count"},{"value":"0","key":"maxElements"},{"value":"0","key":"evictions"},{"value":"Default","key":"policy"}],"id":9}}

# 2  
Old 09-28-2017
Hello Agoyals1986,

Could you please try following and let me know if this helps you.
Code:
 awk -v RS=':|,' '/endTime/{getline;val=val>$0?val:$0} END{print val}'  Input_file

On a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk , /usr/xpg6/bin/awk , or nawk.

Thanks,
R. Singh
# 3  
Old 09-28-2017
Try also
Code:
grep -ho '"endTime":[^,]*' *.tps | sort -r | head -1

# 4  
Old 09-28-2017
Thanks @RudiC working fine on linux but its not working on Solaris

Last edited by Agoyals1986; 09-28-2017 at 12:25 PM..
# 5  
Old 09-28-2017
With perl
Code:
perl -ne 'BEGIN {$search="endTime"; $max=0} if (/"$search":([0-9]*)/ && $1>$max) {$max=$1; $fname=$ARGV;} END {printf "%s \"%s\" %s\n",$fname,$search,$max}' *.tps

Omit what you don't need!

Last edited by MadeInGermany; 09-28-2017 at 01:37 PM..
# 6  
Old 09-28-2017
If you have python installed:-
Code:
import glob
import re

in_file = "*.tps"

e_time = []

for file in glob.glob(in_file):
    with open(file, 'r') as f:
        for line in f:
            pattern = re.search('(?<=endTime":)\w+', line)
            e_time.append(pattern.group(0))

print(max(e_time))

# 7  
Old 09-28-2017
Also for subdirectories:
Code:
find . -name '*.tps' -exec sed '/endTime/!d; s/{//; s/,.*//' {} + | sort -r | head -1

The Following User Says Thank You to Scrutinizer For This Useful Post:
Agoyals1986 (09-29-2017)
Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Not to remove Files based on property value sukhdip Shell Programming and Scripting 3 08-29-2017 09:01 AM
Find keywords in multiple log files dellanicholson UNIX for Dummies Questions & Answers 2 05-31-2016 05:30 PM
Find highest records in table GDC Shell Programming and Scripting 10 07-03-2013 10:47 AM
Script to find & replace a multiple lines string across multiple php files and subdirectories spfc_dmt Shell Programming and Scripting 12 03-07-2012 09:05 AM
Find highest number - working but need help! unknownsolo Shell Programming and Scripting 8 10-21-2011 03:52 PM
Report a missing property and property value mis match script. jayka Shell Programming and Scripting 5 08-24-2011 10:22 AM
Help with find highest and smallest number in a file with c cpp_beginner Programming 2 07-24-2011 10:30 PM
Perl ? - How to find and print the lowest and highest numbers punched in by the user? some124one Shell Programming and Scripting 3 03-29-2008 12:04 PM
Design Options for Property Files jackal28 UNIX for Dummies Questions & Answers 1 11-21-2007 02:25 AM
find the highest number in the file systemali Shell Programming and Scripting 30 03-23-2006 12:31 PM


All times are GMT -4. The time now is 10:46 AM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password