GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: need help in simple scripts
Operating System - HP-UX
1847546
Members
3710
Online
110265
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2003 04:21 PM
10-09-2003 04:21 PM
I am trying to write a ksh script to do data comparison for a flat file. But the data is in decimal e.g. 56.48, 45.68, 56.22, etc.
I tried doing the following but it outputs only the last max value = 55.87. Can some tell me how to do decimal comparison using ksh scripts?
sort -r -k 4,4 xfrdGLOBAL.asc > xfrdGLOBAL.sort
cat xfrdGLOBAL.sort | sed -e '1,$s/ //g' > xfrdGLOBAL.nospace
max_cpu=0
for REC in `cat xfrdGLOBAL.nospace`
do
col_4th=`echo $REC | awk -F'|' '{print $4}'`
if [ $col_4th -gt $max_cpu ]
then
max_cpu=$col_4th
fi
done
echo ""
echo $max_cpu
exit 0
My data file is as follows
09/22/03|00:00| 300| 55.12|
09/22/03|00:05| 299| 54.93|
09/22/03|00:10| 299| 54.91|
09/22/03|00:15| 300| 54.93|
09/22/03|00:20| 299| 54.88|
09/22/03|00:25| 299| 54.88|
09/22/03|00:30| 299| 55.00|
09/22/03|00:35| 299| 54.91|
09/22/03|00:40| 300| 55.95|
09/22/03|00:45| 299| 54.94|
09/22/03|00:50| 299| 55.87|
09/22/03|00:55| 299| 54.88|
I tried doing the following but it outputs only the last max value = 55.87. Can some tell me how to do decimal comparison using ksh scripts?
sort -r -k 4,4 xfrdGLOBAL.asc > xfrdGLOBAL.sort
cat xfrdGLOBAL.sort | sed -e '1,$s/ //g' > xfrdGLOBAL.nospace
max_cpu=0
for REC in `cat xfrdGLOBAL.nospace`
do
col_4th=`echo $REC | awk -F'|' '{print $4}'`
if [ $col_4th -gt $max_cpu ]
then
max_cpu=$col_4th
fi
done
echo ""
echo $max_cpu
exit 0
My data file is as follows
09/22/03|00:00| 300| 55.12|
09/22/03|00:05| 299| 54.93|
09/22/03|00:10| 299| 54.91|
09/22/03|00:15| 300| 54.93|
09/22/03|00:20| 299| 54.88|
09/22/03|00:25| 299| 54.88|
09/22/03|00:30| 299| 55.00|
09/22/03|00:35| 299| 54.91|
09/22/03|00:40| 300| 55.95|
09/22/03|00:45| 299| 54.94|
09/22/03|00:50| 299| 55.87|
09/22/03|00:55| 299| 54.88|
tyl
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2003 04:49 PM
10-09-2003 04:49 PM
Re: need help in simple scripts
Could you explain what you mean by data comparison. As far as I can see, your script appears to try and find the highest value out of a list. It does that successsfully so what are you trying to compare?
Never preceed any demonstration with anything more predictive than "watch this"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2003 05:03 PM
10-09-2003 05:03 PM
Solution
the only thing i can see that might be a problem is the use of [...] which is obsolete. it has been replaced by [[...]] and ((...)).
try using
if (( "$col_4th > "$max_cpu" ))
then
....
but you could do this all within awk
sort -r -k 4,4 xfrdGLOBAL.asc | tr -d " " |
awk -F"|" '{
if ( $4 > max ) max = $4;
} END { print max;}'
try using
if (( "$col_4th > "$max_cpu" ))
then
....
but you could do this all within awk
sort -r -k 4,4 xfrdGLOBAL.asc | tr -d " " |
awk -F"|" '{
if ( $4 > max ) max = $4;
} END { print max;}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2003 05:21 PM
10-09-2003 05:21 PM
Re: need help in simple scripts
your sort should probably be:
sort -r -t"|" -k 4n,4
use "|" as the delimiter between keys
and 4n,4 sort by arithmetic value
and by sorting you probably don't need to do the comparision at all
sort -r -t"|" -k 4n,4 xfrdGLOBAL.asc |
awk -F"|" '{print $4;exit}'
or don't use sort at all
cat xfrdGLOBAL.asc |
awk -F"|" '{
if ( $4 > max ) max = $4;
} END {print $4;}'
sort -r -t"|" -k 4n,4
use "|" as the delimiter between keys
and 4n,4 sort by arithmetic value
and by sorting you probably don't need to do the comparision at all
sort -r -t"|" -k 4n,4 xfrdGLOBAL.asc |
awk -F"|" '{print $4;exit}'
or don't use sort at all
cat xfrdGLOBAL.asc |
awk -F"|" '{
if ( $4 > max ) max = $4;
} END {print $4;}'
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2026 Hewlett Packard Enterprise Development LP