Sponsored Content
Top Forums Shell Programming and Scripting awk search for max and min while ignoring special character Post 302950865 by Don Cragun on Wednesday 29th of July 2015 01:41:18 PM
Old 07-29-2015
For two fields and assuming that line 1 in a file could also be your special character, you could try:
Code:
awk '
NF > 1 {if(!nf++) {
		m1 = M1 = $1
		m2 = M2 = $2
	} else {if($1 + 0 < m1)	m1 = $1
		if($1 + 0 > M1)	M1 = $1
		if($2 + 0 < m2)	m2 = $2
		if($2 + 0 > M2)	M2 = $2
	}
}
END {	print "MinColumn1 MaxColumn1 MinColumn2 MaxColumn2"
	printf("%10s %10s %10s %10s\n", m1, M1, m2, M2)
}' file

which, with your sample input produces the output:
Code:
MinColumn1 MaxColumn1 MinColumn2 MaxColumn2
 -123.7820  -119.9950    39.5520    42.0009

If you want to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk.

PS. Just to be clear, the above code produces the same output if the input file is:
Code:
>
-122.2840   42.0009
-119.9950   41.1777
>
-123.7540   39.5520
-123.7820   39.6872

instead of the provided sample, while the other suggestions in this thread don't seem to produce the desired output in this case. It isn't clear to me from the provided description of the input file format whether or not this matters for the submitter's real world data.

Last edited by Don Cragun; 07-29-2015 at 03:04 PM.. Reason: Add PS.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Awk search for max and min field values

hi, i have an awk script and I managed to figure out how to search the max value but Im having difficulty in searching for the min field value. BEGIN {FS=","; max=0} NF == 7 {if (max < $6) max = $6;} END { print man, min} where $6 is the column of a field separated by a comma (3 Replies)
Discussion started by: Kirichiko
3 Replies

2. UNIX for Dummies Questions & Answers

Iterate a min/max awk script over time-series temperature data

I'm trying to iterate a UNIX awk script that returns min/max temperature data for each day from a monthly weather data file (01_weath.dat). The temperature data is held in $5. The temps are reported each minute so each day contains 1440 temperature enteries. The below code has gotten me as far as... (5 Replies)
Discussion started by: jgourley
5 Replies

3. Shell Programming and Scripting

Ignoring special character while running a job

I am running a program as follows (using uniface) "chngpasswd.sh drg_ldos1 manager64 manager65 SMART2AP" in which manager64 , manager65 is a variables and keeps on changing, above command works fine but in case we have special characters it fails as shown below "chngpasswd.sh drg_ldos1... (3 Replies)
Discussion started by: lalitpct
3 Replies

4. Shell Programming and Scripting

Find min.max value if matching columns found using AWK

Input_ File : 2 3 4 5 1 1 0 1 2 1 -1 1 2 1 3 1 3 1 4 1 6 5 6 6 6 6 6 7 6 7 6 8 5 8 6 7 Desired output : 2 3 4 5 -1 1 4 1 6 5 6 8 5 8 6 7 (3 Replies)
Discussion started by: vasanth.vadalur
3 Replies

5. Shell Programming and Scripting

AWK script - extracting min and max values from selected lines

Hi guys! I'm new to scripting and I need to write a script in awk. Here is example of file on which I'm working ATOM 4688 HG1 PRO A 322 18.080 59.680 137.020 1.00 0.00 ATOM 4689 HG2 PRO A 322 18.850 61.220 137.010 1.00 0.00 ATOM 4690 CD ... (18 Replies)
Discussion started by: grincz
18 Replies

6. Shell Programming and Scripting

Average, min and max in file with header, using awk

Hi, I have a file which looks like this: FID IID MISS_PHENO N_MISS N_GENO F_MISS 12AB43131 12AB43131 N 17774 906341 0.01961 65HJ87451 65HJ87451 N 10149 906341 0.0112 43JJ21345 43JJ21345 N 2826 906341 0.003118I would... (11 Replies)
Discussion started by: kayakj
11 Replies

7. Shell Programming and Scripting

Get the min avg and max with awk

aaa: 3 ms aaa: 2 ms aaa: 5 ms aaa: 10 ms .......... to get the 3 2 5 10 ...'s min avg and max something like min: 2 ms avg: 5 ms max: 10 ms (2 Replies)
Discussion started by: yanglei_fage
2 Replies

8. Shell Programming and Scripting

awk script to find min and max value

I need to find the max/min of columns 1 and 2 of a 2 column file what contains the special character ">". I know that this will find the max value of column 1. awk 'BEGIN {max = 0} {if ($1>max) max=$1} END {print max}' input.file But what if I needed to ignore special characters in the... (3 Replies)
Discussion started by: ncwxpanther
3 Replies

9. Shell Programming and Scripting

How to get min and max values using awk?

Hi, I need your kind help to get min and max values from file based on value in $5 . File1 SP12.3 stc 2240806 2240808 + ID1_N003 ID2_N003T0 SP12.3 sto 2241682 2241684 + ID1_N003 ID2_N003T0 SP12.3 XE 2239943 2240011 + ID1_N003 ID2_N003T0 SP12.3 XE 2240077 2241254 + ID1_N003 ... (12 Replies)
Discussion started by: redse171
12 Replies

10. Shell Programming and Scripting

awk Sort 2d histogram output from min(X,Y) to max(X,Y)

I've got Gnuplot-format 2D histogram data output which looks as follows. 6.5 -1.25 10.2804 6.5404 -1.25 10.4907 6.58081 -1.25 10.8087 6.62121 -1.25 10.4686 6.66162 -1.25 10.506 6.70202 -1.25 10.3084 6.74242 -1.25 9.68256 6.78283 -1.25 9.41229 6.82323 -1.25 9.43078 6.86364 -1.25 9.62408... (1 Reply)
Discussion started by: chrisjorg
1 Replies
truchet(6x)							XScreenSaver manual						       truchet(6x)

NAME
truchet - draws curved or angular Truchet patterns SYNOPSIS
truchet [-display host:display.screen] [-foreground color] [-background color] [-window] [-root] [-mono] [-install] [-visual visual] [-delay milliseconds] [-min-width integer] [-min-height integer] [-max-width integer] [-max-height integer] [-max-linewidth integer] [-min- linewidth integer] [-erase] [-no-erase] [-erase-count integer] [-square] [-not-square] [-curves] [-no-curves] [-angle] [-no-angles] [-scroll] [-scroll-overlap integer] [-anim-delay integer] [-anim-step-size integer] [-fps] DESCRIPTION
The truchet program draws arc and line based Truchet patterns. OPTIONS
truchet accepts the following options: -window Draw on a newly-created window. This is the default. -root Draw on the root window. -mono If on a color display, pretend we're on a monochrome display. -install Install a private colormap for the window. -visual visual Specify which visual to use. Legal values are the name of a visual class, or the id number (decimal or hex) of a specific visual. -delay milliseconds How long to wait between drawing each screenful. Default is 1 seconds. -min-width integer The minimum width in pixels of each square. Default is 40. -min-height integer The minimum height in pixels of each square. Default is 40. -max-width integer The maximum width in pixels of each square. Default is 150. -max-height integer The maximum height in pixels of each square. Default is 150. -max-linewidth integer The maximum width of the lines used to draw. Default is 25. -min-linewidth integer The minimum width of the lines used to draw. Default is 2. -erase -no-erase Whether to clear the screen after each screenful is drawn. Default is True (erase). -erase-count integer The number of screenfuls to draw before erasing. Default is 25. -square -not-square Whether to force the tiles to be square. Default is True (square). -curves -no-curves Whether to draw the arc based Truchet pattern. Default is True (curves). -angles -no-angles Whether or not to draw the line based Truchet pattern. Default is True (angles) -scroll Use the scroll mode. Default is False. -scroll-overlap The amount to scroll from one side to another. Default is 400. -anim-delay The time to pause between each animation step. Default is 100. -anim-step-size The amount of steps to skip between each animation step. Default is 3. -fps Display the current frame rate and CPU load. ENVIRONMENT
DISPLAY to get the default host and display number. XENVIRONMENT to get the name of a resource file that overrides the global resources stored in the RESOURCE_MANAGER property. SEE ALSO
X(1), xscreensaver(1) COPYRIGHT
Copyright (C) 1998 by Adrian Likins. Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, pro- vided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in sup- porting documentation. AUTHOR
Adrian Likins, 1998. X Version 11 5.15 (28-Sep-2011) truchet(6x)
All times are GMT -4. The time now is 03:25 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy