Sponsored Content
Top Forums Shell Programming and Scripting awk Search Array Element Return Index Post 302878869 by Yoda on Monday 9th of December 2013 09:56:10 AM
Old 12-09-2013
Yes, there is no need to initialize variable: v

It is a special kind of for statement for scanning an array.
This User Gave Thanks to Yoda For This Post:
 

10 More Discussions You Might Find Interesting

1. Filesystems, Disks and Memory

why the inode index of file system starts from 1 unlike array index(0)

why do inode indices starts from 1 unlike array indexes which starts from 0 its a question from "the design of unix operating system" of maurice j bach id be glad if i get to know the answer quickly :) (0 Replies)
Discussion started by: sairamdevotee
0 Replies

2. UNIX for Dummies Questions & Answers

wh inode index starts from 1 unlike array index (0)

brothers why inode index starts from 1 unlike array inex which starts from 0 its a question from the design of unix operating system of maurice j.bach i need to know the answer urgently...someone help please (1 Reply)
Discussion started by: sairamdevotee
1 Replies

3. Shell Programming and Scripting

awk array index help

$ cat file.txt A|X|20 A|Y|20 A|X|30 A|Z|20 B|X|10 A|Y|40 Summing up $NF based on first 2 fields, $ awk -F "|" 'BEGIN {OFS="|"} { sum += $NF } END { for (f in sum) print f,sum } ' file.txt o/p: A|X|50 A|Y|60 A|Z|20 (4 Replies)
Discussion started by: uwork72
4 Replies

4. Shell Programming and Scripting

awk: reading into an array and then print the value corresponding to index

I am beginner in awk awk 'BEGIN{for(i=1;(getline<"opnoise")>0;i++) arr=$1}{print arr}' In the above script, opnoise is a file, I am reading it into an array and then printing the value corresponding to index 20. Well this is not my real objective, but I have posted this example to describe... (19 Replies)
Discussion started by: akshaykr2
19 Replies

5. Shell Programming and Scripting

How to check index of a array element in shell script?

Example - Script to find the index of a month from array MONTHS="Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec" set -A MON $MONTHS A="Sun May 23 09:34:30 GMT 2010" getMonth=`echo $A|cut -c5-7` ##getMonth=May Arrayindex_in_MONTHS_array= ???? # { 0,1,2,3,4 } - at fifth place ... (7 Replies)
Discussion started by: KuldeepSinghTCS
7 Replies

6. Shell Programming and Scripting

how to search array and print index in ksh

Hi, I am using KSH shell to do some programming. I want to search array and print index value of the array. Example.. nodeval4workflow="DESCRIPTION ="" ISENABLED ="YES" ISVALID ="YES" NAME="TESTVALIDATION" set -A strwfVar $nodeval4workflow strwfVar=DESCRIPTION=""... (1 Reply)
Discussion started by: tmalik79
1 Replies

7. Shell Programming and Scripting

Search an array and return index (bash)

Hi all, In bash, is there any way of searching an array and returning the index? For example, how could I write a script that would do the following: >> search note_array=(C D E F G A B) for F return the value 3 (or 4) Thanks, R (5 Replies)
Discussion started by: RMontenegro
5 Replies

8. Shell Programming and Scripting

Index problem in associate array in awk

I am trying to reformat the table by filling any missing rows. The final table will have consecutive IDs in the first column. My problem is the index of the associate array in the awk script. infile: S01 36407 53706 88540 S02 69343 87098 87316 S03 50133 59721 107923... (4 Replies)
Discussion started by: yifangt
4 Replies

9. UNIX for Beginners Questions & Answers

Awk: count unique element of array

Hi, tab-separated input: blabla_1 A,B,C,C blabla_2 A,E,G blabla_3 R,Q,A,B,C,R,Q output: blabla_1 3 blabla_2 3 blabla_3 5 After splitting $2 in an array, I am trying to store the number of unique elements in a variable, but have some difficulties resetting the variable to 0 before... (6 Replies)
Discussion started by: beca123456
6 Replies

10. Shell Programming and Scripting

Awk: check element in array and it's value

Hello, I want to see if element exists in array, if so then, check it's corresponding value. Column 4 is position and column 1 is the chromosome for it. There are duplicates for one position on one chromosome. I want to check if same position exists on different chromosome: Data... (8 Replies)
Discussion started by: genome
8 Replies
JudySL(3)						     Library Functions Manual							 JudySL(3)

NAME
JudySL macros - C library for creating and accessing a dynamic array, using a null-terminated string as an Index (associative array) SYNOPSIS
cc [flags] sourcefiles -lJudy #include <Judy.h> #define MAXLINELEN 1000000 // define maximum string length Word_t * PValue; // JudySL array element uint8_t Index[MAXLINELEN]; // string int Rc_int; // return value Word_t Rc_word; // full word return value Pvoid_t PJSLArray = (Pvoid_t) NULL; // initialize JudySL array JSLI( PValue, PJSLArray, Index); // JudySLIns() JSLD( Rc_int, PJSLArray, Index); // JudySLDel() JSLG( PValue, PJSLArray, Index); // JudySLGet() JSLFA(Rc_word, PJSLArray); // JudySLFreeArray() JSLF( PValue, PJSLArray, Index); // JudySLFirst() JSLN( PValue, PJSLArray, Index); // JudySLNext() JSLL( PValue, PJSLArray, Index); // JudySLLast() JSLP( PValue, PJSLArray, Index); // JudySLPrev() DESCRIPTION
A JudySL array is the equivalent of a sorted set of strings, each associated with a Value (word). A Value is addressed by an Index (key), which is a null-terminated character string of any length. Memory to support the array is allocated as index/value pairs are inserted, and released as index/value pairs are deleted. This is a form of associative array, where array elements are also sorted lexicographically (case-sensitive) by indexes. This could be thought of as void * JudySLArray["Toto, I don't think we're in Kansas any more"]; A JudySL array is allocated with a NULL pointer Pvoid_t PJSLArray = (Pvoid_t) NULL; As with an ordinary array, there are no duplicate indexes (strings) in a JudySL array. Using the macros described here, rather than the JudySL function calls, the default error handling sends a message to the standard error and terminates the program with exit(1). JSLI(PValue, PJSLArray, Index) // JudySLIns() Insert an Index string and Value in the JudySL array PJSLArray. If the Index is successfully inserted, the Value is initialized to 0. If the Index was already present, the Value is not modified. Return PValue pointing to Index's Value. Your program must use this pointer to modify the Value, for example: *PValue = 1234; Note: JSLI() and JSLD reorganize the JudySL array. Therefore, pointers returned from previous JudySL calls become invalid and must be reacquired. JSLD(Rc_int, PJSLArray, Index) // JudySLDel() Delete the specified Index/Value pair (array element) from the JudySL array. Return Rc_int set to 1 if successful. array and it was previously inserted. Return Rc_int set to 0 if Index was not present. JSLG(PValue, PJSLArray, Index) // JudySLGet() Get the pointer to Index's Value. Return PValue pointing to Index's Value. Return PValue set to NULL if the Index was not present. JSLFA(Rc_word, PJSLArray) // JudySLFreeArray() Given a pointer to a JudySL array (PJSLArray), free the entire array (much faster than using a JSLN(), JSLD() loop.) Return Rc_word set to the number of bytes freed and PJSLArray set to NULL. JudySL Search Functions The JudySL search functions allow you to search for indexes in the array. You may search inclusively or exclusively, in either forward or reverse directions. If successful, Index is returned set to the found index, and PValue is returned set to a pointer to Index's Value. If unsuccessful, PValue is returned set to NULL, and Index contains no useful information. PValue must be tested for non-NULL prior to using Index, since a search failure is possible. Note: To accomodate all possible returns, the Index buffer must be at least as large as the largest string stored in the array. JSLF(PValue, PJSLArray, Index) // JudySLFirst() Search (inclusive) for the first index present that is equal to or greater than the passed Index string. (Start with a null string to find the first index in the array.) JSLF() is typically used to begin a sorted-order scan of the valid indexes in a JudySL array. uint8_t Index[MAXLINELEN]; strcpy (Index, ""); JSLF(PValue, PJSLArray, Index); JSLN(PValue, PJSLArray, Index) // JudySLNext() Search (exclusive) for the next index present that is greater than the passed Index string. JSLN() is typically used to continue a sorted- order scan of the valid indexes in a JudySL array, or to locate a "neighbor" of a given index. JSLL(PValue, PJSLArray, Index) // JudySLLast() Search (inclusive) for the last index present that is equal to or less than the passed Index string. (Start with a maximum-valued string to look up the last index in the array, such as a max-length string of 0xff bytes.) JSLL() is typically used to begin a reverse-sorted- order scan of the valid indexes in a JudySL array. JSLP(PValue, PJSLArray, Index) // JudySLPrev() Search (exclusive) for the previous index present that is less than the passed Index string. JSLP() is typically used to continue a reverse-sorted-order scan of the valid indexes in a JudySL array, or to locate a "neighbor" of a given index. ERRORS
: See: Judy_3.htm#ERRORS EXAMPLE of a string sort routine #include <stdio.h> #include <Judy.h> #define MAXLINE 1000000 // max string (line) length uint8_t Index[MAXLINE]; // string to insert int // Usage: JudySort < file_to_sort main() { Pvoid_t PJArray = (PWord_t)NULL; // Judy array. PWord_t PValue; // Judy array element. Word_t Bytes; // size of JudySL array. while (fgets(Index, MAXLINE, stdin) != (char *)NULL) { JSLI(PValue, PJArray, Index); // store string into array if (PValue == PJERR) // if out of memory? { // so do something printf("Malloc failed -- get more ram "); exit(1); } ++(*PValue); // count instances of string } Index[0] = ''; // start with smallest string. JSLF(PValue, PJArray, Index); // get first string while (PValue != NULL) { while ((*PValue)--) // print duplicates printf("%s", Index); JSLN(PValue, PJArray, Index); // get next string } JSLFA(Bytes, PJArray); // free array fprintf(stderr, "The JudySL array used %lu bytes of memory ", Bytes); return (0); } AUTHOR
Judy was invented by Doug Baskins and implemented by Hewlett-Packard. SEE ALSO
Judy(3), Judy1(3), JudyL(3), JudyHS(3), malloc(), the Judy website, http://judy.sourceforge.net, for further information and Application Notes. JudySL(3)
All times are GMT -4. The time now is 04:00 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy