answersLogoWhite

0

Write an awk program to search an element from an array?

Updated: 8/17/2019
User Avatar

Wiki User

14y ago

Best Answer

Actually, if you use the awk language with associative arrays there is no need to search for an element of an array:

val["abc"] = 2 ;

will set the element 'abc' in the list 'val' to a value of 2. Since all values start out as blank or 0, finding if an element has a value is easy:

if (val['abc'] == 2)
{
# found the value
}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write an awk program to search an element from an array?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What search begin the search with the first array element?

The search for the first array element begins at the assembly plant. As they array is being constructed, the element itself is one of the first components to be completed.


Write c program to find median?

If you are using an array : sort using qsort() then take middle element.


Write a c program to find the maximum value of 25 element in an array?

int findMax(int *array) { int max = array[0]; for(int i = 1; i < array.length(); i++) { if(array[i] > max) max = array[i] } return max; }


Why you need to sort an array?

Because in any type of search the element can be found at the last position of your array so time complexity of the program is increased..so if array when sorted easily finds the element within less time complexity than before..


How are arrays processed?

Usually one element at a time. If you want to process all elements of an array, you write a loop.Usually one element at a time. If you want to process all elements of an array, you write a loop.Usually one element at a time. If you want to process all elements of an array, you write a loop.Usually one element at a time. If you want to process all elements of an array, you write a loop.


How do you write a program which reads a list of ten numbers and print the list in reserve order in c program?

The simplest way is probably to read the numbers into an array and then prints each element of the array starting at the last one and moving backwards.


How do you write the program to search for a word in an array of 5 words?

Write a loop that compares the word with every word in the array. For example, in Java, I think it would be something like this: // Declare some variables here ... for (int i = 0; i


How can you search an array element in a file?

Logic to search element in array Input size and elements in array from user. ... Input number to search from user in some variable say toSearch . Define a flag variable as found = 0 . ... Run loop from 0 to size . ... Inside loop check if current array element is equal to searched number or not. To learn more about data science please visit- Learnbay.co


Write a program in c to find the largest no out of a matrix of order mn?

/* using ellipses (...) to indicate tabs for clarity */ double largest (double *array, int M, int N) { ... int i, j; ... double *element; ... double answer = array[0][0]; ... for (i=0; i<M; i++) { ... ... for (j=0; j<N; j++) { ... ... ... element = array + i*M + j; ... ... ... if (*element > answer) answer = *element; ... ... } ... } ... return answer; }


Write a program to find out the address of an element in an array?

== Java does not allow reference to memory locations. == In C: for (i=0; i<n; ++i) printf ("a[%d] is at %p\n", i, &a[i]);


How do i write a program in c langua ge for the implementation of binary search with output?

There are various ways to implement a binary search, but the simplest makes use of a sorted array. It must be sorted because we need to know where values are in relation to one another. That is, if we know that element X has the value Y, then all values less than Y must be in the first half of the array, and all values greater than Y must be in the second half of the array. We begin by looking at the middle element of the array. If there is no middle element (the array is empty) then the value does not exist. But if the middle value holds the value we are looking for, we are done. Otherwise we compare values to decide which half of the array can be eliminated. We then repeat the process with the remaining half of the array.


How do you search for an element in unsorted array?

Let's use integers as an example. int elementToFind; // the element we want to search for int[] elementArray; // the array we want to search through boolean found = false; //boolean flag to indicate if we found the element or not for(int i = 0; i < elementArray.length; ++i) { if(elementArray[i] == elementToFind) { // we found the element at index i // do whatever you want to do with this information found = true; } //if found is still false so it means this element is not found if(!found) { //the element is not found in the array } }