Sponsored Content
Top Forums Shell Programming and Scripting Generate sorted awk array for further processing Post 303025211 by Ophiuchus on Saturday 27th of October 2018 09:14:08 PM
Old 10-27-2018
Generate sorted awk array for further processing

Hello to all,

I have and input file like this:
Code:
Objects (id: bounding-box centroid area mean-color):
  0: 800x800+0+0 406.6,390.9 378792 srgb(0,0,0)
  11: 240x151+140+624 259.5,699.0 36240 srgb(255,255,255)
  6: 240x151+462+176 581.5,251.0 36240 srgb(255,255,255)
  7: 240x151+87+257 206.5,332.0 36240 srgb(255,255,255)
  8: 240x151+366+355 485.5,430.0 36240 srgb(255,255,255)
  9: 240x151+77+448 196.5,523.0 36240 srgb(255,255,255)
  10: 240x151+468+542 587.5,617.0 36240 srgb(255,255,255)
  2: 178x59+223+65 311.5,94.0 10502 srgb(255,255,255)
  3: 178x59+417+65 505.5,94.0 10502 srgb(255,255,255)
  4: 178x59+611+65 699.5,94.0 10502 srgb(255,255,255)
  1: 178x59+29+65 117.5,94.0 10502 srgb(255,255,255)
  5: 110x16+255+63 309.5,182.5 1760 srgb(255,255,255)

I'm interested in second field, for example the second element of second field is "240x151+140+624". If we use as field separator "+" for this second field, then would be 3 subfields within original 2nd field.

I want to have and awk array (in this case array "a") with this 2nd field sorted first by 3rd subfield and then by second subfield (where new FS="+").

I'm doing this and it works with the code below but I need first an awk program, then pipe to sort command then pipe again for the 2nd awk program.

Code:
  
awk 'NR>2{print $2}' file | sort -t "+" -k3n -k2n |  
awk '{a[NR]=$0} END{for (i=1;i<=length(a);i++) print a[i] }'
110x16+255+63
178x59+29+65
178x59+223+65
178x59+417+65
178x59+611+65
240x151+462+176
240x151+87+257
240x151+366+355
240x151+77+448
240x151+468+542
240x151+140+624

How to get the sorted array "a" in a single awk program (without pipe twice) to be able to make further processing in the END{} block?

Thanks in advance
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove lines, Sorted with Time based columns using AWK & SORT

Hi having a file as follows MediaErr.log 84 Server1 Policy1 Schedule1 master1 05/08/2008 02:12:16 84 Server1 Policy1 Schedule1 master1 05/08/2008 02:22:47 84 Server1 Policy1 Schedule1 master1 05/08/2008 03:41:26 84 Server1 Policy1 ... (1 Reply)
Discussion started by: karthikn7974
1 Replies

2. Shell Programming and Scripting

Sorted list by time of spu processing

Hi, i have to make a command in unix system which make a sorted list by cpu time (not %cpu ). If the application exists more than a time I would like to keep only one copy. Could you help me please ??? P.s : I am trying --> ps aux --sort -%cpu | uniq but I understand that is wrong (5 Replies)
Discussion started by: petros55
5 Replies

3. Shell Programming and Scripting

Generate array name at run time Korn shell

Hi, I am trying to define number of array based on constant derived during execution phase of a script. Here is what i am trying.. #First Part, Get LUN input from User lun_count=4 count=0 set -A my_lun while : do while ]; do read L?"Enter Lun "$count" Number:" ... (2 Replies)
Discussion started by: harris2107
2 Replies

4. Shell Programming and Scripting

Generate command with awk

Hello, I have the line underneath generated by lssyscfg command: """51/client/1/pcyaz0hjfv00-vio1/651/c050760107fd0466,c050760107fd0467/1"",""52/client/2/pcyaz0hjfv01-vio2/652/c050760107fd0468,c050760107fd0469/1"",""31/client/1/pcyaz0hjfv00-vio1/375/c050760107fd046a,c050760107fd046b/1"""... (1 Reply)
Discussion started by: khalidou13
1 Replies

5. UNIX for Dummies Questions & Answers

Help with printing sorted array of numbers

Dear All, I am trying to sort an array of numbers to retrieve the mimimum and maximum values of numbers in that array, by printing the first and last elements of the sorted array. My code is @sorted_numbers = sort (@numbers); print "@sorted_numbers\n"; print "$sorted_numbers,... (0 Replies)
Discussion started by: pawannoel
0 Replies

6. Programming

generate array of random numbers

hi guys, I am writing a c program that generates a two dimensional array to make matrix and a vector of random numbers and perform multiplication. I can't figure out whats wrong with my code. It generates a matrix of random numbers but all the numbers in the vector array is same and so is the... (2 Replies)
Discussion started by: saboture88
2 Replies

7. Shell Programming and Scripting

How do I put data piped to my script into an array for repeated processing

Hi folks, Sorry for something I'm sure was answered already, I just could not find it in a search of the forums. I am trying to build a script that eats a config file as: cat file.cnf | ConProcess.shWhat I want to do inside the script is: !#/usr/bin/bash # captured piped cat into an... (6 Replies)
Discussion started by: Marc G
6 Replies

8. Programming

awk processing / Shell Script Processing to remove columns text file

Hello, I extracted a list of files in a directory with the command ls . However this is not my computer, so the ls functionality has been revamped so that it gives the filesizes in front like this : This is the output of ls command : I stored the output in a file filelist 1.1M... (5 Replies)
Discussion started by: ajayram
5 Replies

9. Shell Programming and Scripting

How to Assign an shell array to awk array?

Hello All, Can you please help me with the below. #!/bin/bash ARR="No Differences In Stage Between HASH_TOTALS & HASH_TOTALS_COMP For UNINUM:0722075 PROVIDER:5 EXTRACT_DT:30-SEP-12 VER_NUM:1" ARR="No Differences In Stage Between HASH_TOTALS & HASH_TOTALS_COMP For UNINUM:0722075 PROVIDER:5... (14 Replies)
Discussion started by: Ariean
14 Replies

10. UNIX for Beginners Questions & Answers

awk use to generate report

Hi , In a directory list of ddl files are stored in the given format above. Above is the sample ddl file. The ddl file name is same as that of table name ie email_notifications.ddl I want to generate below report using awk utility reading all the ddl files stored in /ddl path Desired output:... (1 Reply)
Discussion started by: vedanta
1 Replies
IGAWK(1)							 Utility Commands							  IGAWK(1)

NAME
igawk - gawk with include files SYNOPSIS
igawk [ all gawk options ] -f program-file [ -- ] file ... igawk [ all gawk options ] [ -- ] program-text file ... DESCRIPTION
Igawk is a simple shell script that adds the ability to have ``include files'' to gawk(1). AWK programs for igawk are the same as for gawk, except that, in addition, you may have lines like @include getopt.awk in your program to include the file getopt.awk from either the current directory or one of the other directories in the search path. OPTIONS
See gawk(1) for a full description of the AWK language and the options that gawk supports. EXAMPLES
cat << EOF > test.awk @include getopt.awk BEGIN { while (getopt(ARGC, ARGV, "am:q") != -1) ... } EOF igawk -f test.awk SEE ALSO
gawk(1) Effective AWK Programming, Edition 1.0, published by the Free Software Foundation, 1995. AUTHOR
Arnold Robbins (arnold@skeeve.com). ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +--------------------+-----------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +--------------------+-----------------+ |Availability | SUNWgawk | +--------------------+-----------------+ |Interface Stability | Volatile | +--------------------+-----------------+ NOTES
Source for gawk is available on http://opensolaris.org. Free Software Foundation Nov 3 1999 IGAWK(1)
All times are GMT -4. The time now is 09:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy