Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7611515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:41:01+00:00 2026-05-31T01:41:01+00:00

How can I find the maximum element and its index from an array in

  • 0

How can I find the maximum element and its index from an array in shell script. I have an array

a = [-2.2116565098 -2.1238242060 -2.1747941240 -2.3201010162 -2.3677779871 -1.8126464132 -2.1247209755 -2.1190930712 -2.3242384636 -2.1081702064];

Now, I want to find the maximum as well as its index in bash script. Is there a shortcut like in Matlab we have

[C, I] = max(a);

Also, also how can we have multi-dimensional array and get the index and value of minimum and maximum element.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T01:41:02+00:00Added an answer on May 31, 2026 at 1:41 am
    $ x='-2.2116565098 -2.1238242060 -2.1747941240 -2.3201010162 -2.3677779871'
    $ IC=(`tr ' ' '\n' <<<$x | cat -n | sort -k2,2nr | head -n1`)
    $ I=${IC[0]} C=${IC[1]}
    $ echo $I $C
    2 -2.1238242060
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code is about to find maximum element from an array i want to
A PHP array can have arrays for its elements. And those arrays can have
I have made a matrix using vector and iterator, how can I find maximum
Where can I find what is the maximum identifier length in C? In which
How can I find the high water mark (the historical maximum number of concurrent
I'm tring to find the maximum weight subsequence of an array of positive integers
I have to find a way to display the Maximum and Minium number in
I can find tutorials about mapping textures to polygons specifying vertices etc. but nothing
I can find lots of information on how Long Polling works (For example, this
I can find a direct table foreign key in c# like: foreach (ForeignKey key

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.