Gawk: PROCINFO["sorted_in"] does not sort my numerical array values


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Gawk: PROCINFO["sorted_in"] does not sort my numerical array values
# 1  
Old 04-21-2018
Gawk: PROCINFO["sorted_in"] does not sort my numerical array values

Hi,

PROCINFO seems to be a great function but I don't manage to make it works.

input:
Code:
B,A,C
B
B,B

As an example, just want to count the occurence of each letter across the input and sort them by decreased order.

Wanted output:
Code:
B 4
A 1
C 1

When I use this command, the PROCINFO does not have any effect:
Code:
echo -e "B,A,C\nB\nB,B" | gawk '{a=split($0,b,","); for(i=1; i<=a; i++){count[b[i]]++}}END{PROCINFO["sorted_in"]="@_val_num_desc"; for(k in count){print k FS count[k]}}'

I get this output:
Code:
A 1
B 4
C 1

Could someone explain me what I am doing wrong?

Thanks !

Last edited by beca123456; 04-21-2018 at 06:48 AM..
# 2  
Old 04-21-2018
Try "@val_num_desc"
This User Gave Thanks to RudiC For This Post:
# 3  
Old 04-21-2018
Sorry, I am stupid...

No "_" between "@" and "val"

Sorry again

Note: I had to upgrade gawk to version 4 to get PROCINFO working
This User Gave Thanks to beca123456 For This Post:
# 4  
Old 04-21-2018
Thanks for letting us know
# 5  
Old 04-21-2018
So - problem persists? Solved?

EDIT: Seems solved by now... Methinks part of the problem was the gawk version...

Last edited by RudiC; 04-21-2018 at 07:05 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. UNIX for Beginners Questions & Answers

Extract delta records using with "comm" and "sort" commands combination

Hi All, I have 2 pipe delimited files viz., file_old and file_new. I'm trying to compare these 2 files, and extract all the different rows between them into a new_file. comm -3 < sort file_old < sort file_new > new_file I am getting the below error: -ksh: sort: cannot open But if I do... (7 Replies)
Discussion started by: njny
7 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. Shell Programming and Scripting

Is it Possible to sort a list of hexadecimal numbers using "sort" command?

Hello Everybody :) !!!. i have question in mind, is it possible to sort a list of hexadecimal numbers using "sort" command? (9 Replies)
Discussion started by: Kesavan
9 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. Shell Programming and Scripting

Meaning of "b" modifier in "sort" command

I need to sort the following file by the rhdiskpower devices in the last column: Total_MB Free_MB OS_MB Name Failgroup Library Label UDID Product Redund Path 1024 851 1024 OCRVOT1_0000 OCRVOT1_0000 System UNKNOWN ... (3 Replies)
Discussion started by: wjssj
3 Replies

7. Shell Programming and Scripting

substituting the character ")" in gawk

Hi, I am using gawk to substitute the character ")" with ")\n" using sub function but it gives me the following error: gawk: cmd. line:3: (FILENAME= FNR=11) fatal: Unmatched \):/),/ The command is: gawk ' /^*function.*\(/,/\)/{sub(")",")\n")} ' (1 Reply)
Discussion started by: ghoda2_10
1 Replies

8. Programming

C: Initialize "const" array from the "heap"

Hello, I am working on solving an NP-Complete problem, so it is very important that operations and data with limited integer-argument ranges be computed using immutable look-up-tables contained entirely in CPU cache. Retrieval of the look-up-table data must never leave the CPU once initially... (6 Replies)
Discussion started by: HeavyJ
6 Replies

9. Shell Programming and Scripting

if [ "variable" = "numerical-range" ]; then

been a while so i'm a bit rusty and need a little help. writing a script that needs to compare $EXECHOST(a number) against a numerical range and then set a value. below isn't working but should give you folks an idea of my goal: if ; then echo "This is a 32B machine, exiting..." if ;... (4 Replies)
Discussion started by: crimso
4 Replies
Login or Register to Ask a Question