Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Java - Arrays.binarySearch function equivalent in awk

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 09-13-2013
Akshay Hegde's Unix or Linux Image
Akshay Hegde Akshay Hegde is offline Forum Advisor  
Forum Advisor
 
Join Date: Nov 2012
Last Activity: 22 May 2015, 12:12 AM EDT
Location: Goa / Bangalore, India
Posts: 1,710
Thanks: 84
Thanked 575 Times in 524 Posts
Java - Arrays.binarySearch function equivalent in awk

Hi all

Does anyone know Java-Arrays.binarySearch function equivalent in awk
I tried like this but it's not correct one,it just returns array index if and only when searched value available in array, for some reason if searched value not found then I want to return upper nearest neighbour index. please let me know if anyone have better idea


Code:
function Arrays_binarySearch(arr,val){
                    
                    for(b in arr){
                    if(arr[b]==val)
                             return b
                             break
                             }    
                    
                     }

here is link to example in java

Java.util.Arrays.binarySearch(int[] a, int key) Method Example

please someone help me..

Last edited by Akshay Hegde; 09-13-2013 at 11:49 AM..
Sponsored Links
    #2  
Old Unix and Linux 09-13-2013
spacebar's Unix or Linux Image
spacebar spacebar is offline
Registered User
 
Join Date: Oct 2009
Last Activity: 2 June 2014, 3:23 PM EDT
Location: spaceBAR Central
Posts: 440
Thanks: 0
Thanked 70 Times in 70 Posts
Check out this info there are examples for multiple languages:
Binary search - Rosetta Code
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Equivalent function for matlab on scilab abu_malek Programming 0 09-18-2009 10:58 AM
shell script equivalent for tcl function JackMelson Shell Programming and Scripting 1 11-30-2008 04:55 PM
Bash equivalent of perl's pack function ? NewDeb Shell Programming and Scripting 1 11-14-2008 10:23 PM
equivalent function for wherey( ) ?? rockgal Programming 2 11-28-2006 08:13 AM
Equivalent function of [ kbhit() ] In TURBO C niravuchat Linux 0 03-22-2004 08:16 AM



All times are GMT -4. The time now is 03:19 PM.