Today's Posts

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


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.

"endTime :1488902691462"


# 2  
Old 09-28-2017
Hello Agoyals1986,

Could you please try following and let me know if this helps you.
 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.

R. Singh
# 3  
Old 09-28-2017
Try also
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 01:25 PM..
# 5  
Old 09-28-2017
With perl
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 02:37 PM..
# 6  
Old 09-28-2017
If you have python installed:-
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)


# 7  
Old 09-28-2017
Also for subdirectories:
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 10:01 AM
Find highest records in table GDC Shell Programming and Scripting 10 07-03-2013 11:47 AM
Find values in multiple csv files biscayne Shell Programming and Scripting 6 01-04-2013 10:49 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 10:05 AM
Find highest number - working but need help! unknownsolo Shell Programming and Scripting 8 10-21-2011 04:52 PM
Report a missing property and property value mis match script. jayka Shell Programming and Scripting 5 08-24-2011 11:22 AM
Help with find highest and smallest number in a file with c cpp_beginner Programming 2 07-24-2011 11: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 01:04 PM
Design Options for Property Files jackal28 UNIX for Dummies Questions & Answers 1 11-21-2007 03:25 AM
find the highest number in the file systemali Shell Programming and Scripting 30 03-23-2006 01:31 PM

All times are GMT -4. The time now is 10:04 PM.

Unix & Linux Forums Content Copyright 1993-2018. All Rights Reserved.
Show Password