Sponsored Content
Full Discussion: Sorting from file
Top Forums Shell Programming and Scripting Sorting from file Post 302964074 by RudiC on Saturday 9th of January 2016 06:38:08 PM
Old 01-09-2016
Not sure I understand those extra periods' evaluation.

And, why do you think sorting is essential?

Try this as a starting point:
Code:
awk -F: '
NR==1   {print "Points\tTeam\tMatches \tWins\tTies\tLosses"
         for (n = split ($0, TEAM); n > 0; n--) POINTS[TEAM[n]]=0
         next
        }

/^Round/        {next}

        {    split ($2, TM, "-")
             split ($3, RE, "-")
         P = split ($4, PR, ",")
         if (P > 3)             {POINTS[TM[1]]++
                                 POINTS[TM[2]]++
                                 TIES[TM[1]]++
                                 TIES[TM[2]]++
                                 VAL = 1
                                }
         else                    VAL = 3

         if (RE[1] > RE[2])     {POINTS[TM[1]] += VAL
                                 WINS[TM[1]]++
                                 LOSSES[TM[2]]++
                                }
         if (RE[1] < RE[2])     {POINTS[TM[2]] += VAL
                                 WINS[TM[2]]++
                                 LOSSES[TM[1]]++
                                }
        }
END     {for (p in POINTS) print POINTS[p], p, MATCHES[p], WINS[p]+0, TIES[p]+0, LOSSES[p]+0
        }
' OFS="\t" file
Points	Team	Matches 	Wins	Ties	Losses
3	Frölunda HC		1	0	1
3	MIF Redhawks		1	0	1
3	Färjestads BK		1	0	1
0	MODO Hockey		0	0	2
0	Leksands IF		0	0	2
2	Djurgårdens IF		1	1	1
1	Södertälje SK		0	1	2
6	Timrå IK		2	0	0
3	Luleå HF		1	0	1
6	Brynäs IF		2	0	0
6	HV 71		2	0	0
3	Linköpings HC		1	0	1

This User Gave Thanks to RudiC For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help sorting file.

Hi, I have this file (filex) 07-11-2003 10:11:12!cccc!ddd!eeeeeeee 07-11-2003 09:11:11!dddd!kkkkk!xxxxxx 09-12-2003 14:18:43!aaaa!bbbbb!cccc where I need to sort it by date+time in this order: 09-12-2003 14:18:43!aaaa!bbbbb!cccc 07-11-2003 10:11:12!cccc!ddd!eeeeeeee 07-11-2003... (3 Replies)
Discussion started by: gio123bg
3 Replies

2. Shell Programming and Scripting

sorting file

hi everyone, i have a document where i have email addresess and names, i need to check if the email addresses are uniq, if they repeat erase one of them, how can i do that? document sample: aD00763357@cucei.udg.mx,ABRAHAM ANTONIO SEVERIANO a199721111@cucei.udg.mx,ABRAHAM GONZALEZ... (4 Replies)
Discussion started by: sx3v1l_1n51de
4 Replies

3. Programming

regarding file sorting

i ahve a file like: ************************************* sree 122132 12321 *********************************** phani 21321 3213214 ****************************** dddsds 213213123 23213213 ******************************* i want to sort the file with respect to name how we can do this... (1 Reply)
Discussion started by: phani_sree
1 Replies

4. Shell Programming and Scripting

file sorting

i have a data in afile like this ************************************** sree sree@yahoo.com 98662323432 ************************************* phani phani@yahoo.com 98662323344 ************************************* i want to sort the file with respect to name. how can i do this. thank... (5 Replies)
Discussion started by: phani_sree
5 Replies

5. Shell Programming and Scripting

Sorting file

I have the file as follow: A: 60 B: 80 C: 40 D: 11 E: 100 I want to sort the file and get the output to file as follow: E: 100 B: 80 A: 60 C: 40 D: 11 Could any one help me please? (1 Reply)
Discussion started by: moutaz1983
1 Replies

6. Shell Programming and Scripting

Finding & Moving Oldest File by Parsing/Sorting Date Info in File Names

I'm trying to write a script that will look in an /exports folder for the oldest export file and move it to a /staging folder. "Oldest" in this case is actually determined by date information embedded in the file names themselves. Also, the script should only move a file from /exports to... (6 Replies)
Discussion started by: nikosey
6 Replies

7. UNIX for Dummies Questions & Answers

sorting s file

how would i sort a file on the third column based on numerical value instead of the ASCII order? (1 Reply)
Discussion started by: trob
1 Replies

8. UNIX for Dummies Questions & Answers

Sorting data in file based on field in another file

Hi, I have two files, one of which I would like to sort based on the order of the data in the second. I would like to do this using a simple unix statement. My two files as follows: File 1: 12345 1 2 2 2 0 0 12349 0 0 2 2 1 2 12350 1 2 1 2 2 2 . . . File2: 12350... (3 Replies)
Discussion started by: kasan0
3 Replies

9. Solaris

What about sorting a 5G file?

Hi Guys, My client (dear clients, I hate to love you) has the funky idea of sorting a 5G flat file. Certainly enough, this is taking forever and also fulls the / of our machine. Any idea of how we could proceed to make this a little bit more efficient? Maybe by forcing sort to "stay in... (7 Replies)
Discussion started by: plmachiavel
7 Replies

10. Shell Programming and Scripting

Need help in Sorting a file

Hi Unix Admins, I wanted to sort a file in a specific order, i.e the input file contains two fields and the first column is not unique and had to be sorted. example Input File ------- 2014-10-21:Rand1 2014-11-02:Rand2 2014-11-02:Rand3 2014-11-02:Rand4 2014-11-03:Rand5 2014-11-04:Rand6... (4 Replies)
Discussion started by: Naveenezone
4 Replies
Math::Polygon(3pm)					User Contributed Perl Documentation					Math::Polygon(3pm)

NAME
Math::Polygon - Class for maintaining polygon data SYNOPSIS
my $poly = Math::Polygon->new( [1,2], [2,4], [5,7], [1,2] ); print $poly->nrPoints; my @p = $poly->points; my ($xmin, $ymin, $xmax, $ymax) = $poly->bbox; my $area = $poly->area; my $l = $poly->perimeter; if($poly->isClockwise) { ... }; my $rot = $poly->startMinXY; my $center = $poly->centroid; if($poly->contains($point)) { ... }; my $boxed = $poly->lineClip($xmin, $xmax, $ymin, $ymax); DESCRIPTION
This class provides an OO interface around Math::Polygon::Calc and Math::Polygon::Clip. METHODS
Constructors $obj->new([OPTIONS], [POINTS], [OPTIONS]) Math::Polygon->new([OPTIONS], [POINTS], [OPTIONS]) You may add OPTIONS after and/or before the POINTS. You may also use the "points" options to get the points listed. POINTS are references to an ARRAY of X and Y. When "new" is called as instance method, it is believed that the new polygon is derived from the callee, and therefore some facts (like clockwise or anti-clockwise direction) will get copied unless overruled. -Option --Default bbox undef clockwise undef points undef bbox => ARRAY Usually computed from the figure automatically, but can also be specified as [xmin,ymin,xmax, ymax]. See bbox(). clockwise => BOOLEAN Is not specified, it will be computed by the isClockwise() method on demand. points => ARRAY-OF-POINTS See points() and nrPoints(). example: creation of new polygon my $p = Math::Polygon->new([1,0],[1,1],[0,1],[0,0],[1,0]); my @p = ([1,0],[1,1],[0,1],[0,0],[1,0]); my $p = Math::Polygon->new(points => @p); Attributes $obj->nrPoints Returns the number of points, $obj->order Returns the number of uniqe points: one less than nrPoints(). $obj->point(INDEX, [INDEX, ...]) Returns the point with the specified INDEX or INDEXES. In SCALAR context, only the first INDEX is used. $obj->points In LIST context, the points are returned as list, otherwise as reference to an ARRAY. Geometry $obj->area Returns the area enclosed by the polygon. The last point of the list must be the same as the first to produce a correct result. The computed result is cached. Function Math::Polygon::Calc::polygon_area(). $obj->bbox Returns a list with four elements: (xmin, ymin, xmax, ymax), which describe the bounding box of the polygon (all points of the polygon are inside that area). The computation is expensive, and therefore, the results are cached. Function Math::Polygon::Calc::polygon_bbox(). $obj->beautify(OPTIONS) Returns a new, beautified version of this polygon. Function Math::Polygon::Calc::polygon_beautify(). Polygons, certainly after some computations, can have a lot of horrible artifacts: points which are double, spikes, etc. This functions provided by this module beautify -Option --Default remove_spikes <false> remove_spikes => BOOLEAN $obj->centroid Returns the centroid location of the polygon. The last point of the list must be the same as the first to produce a correct result. The computed result is cached. Function Math::Polygon::Calc::polygon_centroid(). $obj->clockwise Make sure the points are in clockwise order. $obj->contains(POINT) Returns a truth value indicating whether the point is inside the polygon or not. On the edge is inside. $obj->counterClockwise Make sure the points are in counter-clockwise order. $obj->equal((OTHER|ARRAY, [TOLERANCE])|POINTS) Compare two polygons, on the level of points. When the polygons are the same but rotated, this will return false. See same(). Function Math::Polygon::Calc::polygon_equal(). $obj->isClockwise The points are (in majority) orded in the direction of the hands of the clock. This calculation is quite expensive (same effort as calculating the area of the polygon), and the result is therefore cached. $obj->isClosed Returns true if the first point of the poly definition is the same as the last point. $obj->perimeter The length of the line of the polygon. This can also be used to compute the length of any line: of the last point is not equal to the first, then a line is presumed; for a polygon they must match. Function Math::Polygon::Calc::polygon_perimeter(). $obj->same((OTHER|ARRAY, [TOLERANCE])|POINTS) Compare two polygons, where the polygons may be rotated wrt each other. This is (much) slower than equal(), but some algorithms will cause un unpredictable rotation in the result. Function Math::Polygon::Calc::polygon_same(). $obj->startMinXY Returns a new polygon object, where the points are rotated in such a way that the point which is losest to the left-bottom point of the bouding box has become the first. Function Math::Polygon::Calc::polygon_start_minxy(). Transformations Implemented in Math::Polygon::Transform: changes on the structure of the polygon except clipping. All functions return a new polygon object or undef. $obj->grid(OPTIONS) Returns a polygon object with the points snapped to grid points. See Math::Polygon::Transform::polygon_grid(). -Option--Default raster 1.0 raster => FLOAT The raster size, which determines the points to round to. The origin "[0,0]" is always on a grid-point. When the raster value is zero, no transformation will take place. $obj->mirror(OPTIONS) Mirror the polygon in a line. Only one of the options can be provided. Some programs call this "flip" or "flop". -Option--Default b 0 line <undef> rc undef x undef y undef b => FLOAT Only used in combination with option "rc" to describe a line. line => [POINT, POINT] Alternative way to specify the mirror line. The "rc" and "b" are computed from the two points of the line. rc => FLOAT Description of the line which is used to mirror in. The line is "y= rc*x+b". The "rc" equals "-dy/dx", the firing angle. If "undef" is explicitly specified then "b" is used as constant x: it's a vertical mirror. x => FLOAT Mirror in the line "x=value", which means that "y" stays unchanged. y => FLOAT Mirror in the line "y=value", which means that "x" stays unchanged. $obj->move(OPTIONS) Returns a moved polygon object: all point are moved over the indicated distance. See Math::Polygon::Transform::polygon_move(). -Option--Default dx 0 dy 0 dx => FLOAT Displacement in the horizontal direction. dy => FLOAT Displacement in the vertical direction. $obj->resize(OPTIONS) Returns a resized polygon object. See Math::Polygon::Transform::polygon_resize(). -Option--Default center [0,0] scale 1.0 xscale <scale> yscale <scale> center => POINT scale => FLOAT Resize the polygon with the indicated factor. When the factor is larger than 1, the resulting polygon with grow, when small it will be reduced in size. The scale will be respective from the center. xscale => FLOAT Specific scaling factor in the horizontal direction. yscale => FLOAT Specific scaling factor in the vertical direction. $obj->rotate(OPTIONS) Returns a rotated polygon object: all point are moved over the indicated distance. See Math::Polygon::Transform::polygon_rotate(). -Option --Default center [0,0] degrees 0 radians 0 center => POINT degrees => FLOAT specify rotation angle in degrees (between -180 and 360). radians => FLOAT specify rotation angle in rads (between -pi and 2*pi) $obj->simplify(OPTIONS) Returns a polygon object where points are removed. See Math::Polygon::Transform::polygon_simplify(). -Option --Default max_points undef same 0.0001 slope undef max_points => INTEGER First, "same" and "slope" reduce the number of points. Then, if there are still more than the specified number of points left, the points with the widest angles will be removed until the specified maximum number is reached. same => FLOAT The distance between two points to be considered "the same" point. The value is used as radius of the circle. slope => FLOAT With three points X(n),X(n+1),X(n+2), the point X(n+1) will be removed if the length of the path over all three points is less than "slope" longer than the direct path between X(n) and X(n+2). The slope will not be removed around the starting point of the polygon. Removing points will change the area of the polygon. Clipping $obj->fillClip1(BOX) Clipping a polygon into rectangles can be done in various ways. With this algorithm, the parts of the polygon which are outside the BOX are mapped on the borders. The polygon stays in one piece, but may have vertices which are followed in two directions. Returned is one polygon, which is cleaned from double points, spikes and superfluous intermediate points, or "undef" when no polygon is outside the BOX. Function Math::Polygon::Clip::polygon_fill_clip1(). $obj->lineClip(BOX) Returned is a list of ARRAYS-OF-POINTS containing line pieces from the input polygon. Function Math::Polygon::Clip::polygon_line_clip(). Display $obj->string SEE ALSO
This module is part of Math-Polygon distribution version 1.02, built on September 19, 2011. Website: http://perl.overmeer.net/geo/ LICENSE
Copyrights 2004,2006-2011 by Mark Overmeer. For other contributors see ChangeLog. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://www.perl.com/perl/misc/Artistic.html perl v5.12.4 2011-09-19 Math::Polygon(3pm)
All times are GMT -4. The time now is 06:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy