Sponsored Content
Full Discussion: Array to array scanning
Top Forums Shell Programming and Scripting Array to array scanning Post 303011412 by RudiC on Thursday 18th of January 2018 05:51:28 AM
Old 01-18-2018
The split statement creates an array whose elements have the values of the substrings (separated by the FS) and consecutive indices starting from 1.
The individual assignments each create an associative array (sometimes also called hash) element with an individual string index and, here, an empry value. Example:
Code:
awk 'BEGIN      {split("80 25 443 6010",Q)
                 for (i in Q) print "index:", i, ", value:", Q[i]
                 q["80"]; q["25"]; q["443"];q["6010"]
                 for (i in q) print "index:", i, ", value:", q[i]
                }
'
index: 1 , value: 80
index: 2 , value: 25
index: 3 , value: 443
index: 4 , value: 6010
index: 25 , value: 
index: 80 , value: 
index: 443 , value: 
index: 6010 , value:

With a little trick, you can create an associative array from a (separated) string:
Code:
awk 'BEGIN      {for (n=split("80 25 443 6010", q); n>0; n--) Q[q[n]] 
                 for (i in Q) print "index:", i, ", value:", Q[i]
                }
index: 25 , value: 
index: 80 , value: 
index: 443 , value: 
index: 6010 , value:


Last edited by RudiC; 01-18-2018 at 06:57 AM..
This User Gave Thanks to RudiC For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Percent complete error while scanning RAID array during 5.0.6 load

Percent complete SCO 5.0.6 / No longer an issue (0 Replies)
Discussion started by: Henrys
0 Replies

2. Shell Programming and Scripting

create array holding characters from sring then echo array.

Hi, I wish to store $string1 in $string1array a character in each array element. Then i wish to echo the entire array to the screen so that it reads as the normal string again. I have been trying with the code below but does not work. Please help... To put string into array: ... (5 Replies)
Discussion started by: rorey_breaker
5 Replies

3. Programming

Creating an array to hold posix thread ids: Only dynamic array works

I am facing a strange error while creating posix threads: Given below are two snippets of code, the first one works whereas the second one gives a garbage value in the output. Snippet 1 This works: -------------- int *threadids; threadids = (int *) malloc (num_threads * sizeof(int)); ... (4 Replies)
Discussion started by: kmehta
4 Replies

4. Shell Programming and Scripting

PHP: Search Multi-Dimensional(nested) array and export values of currenly worked on array.

Hi All, I'm writing a nagios check that will see if our ldap servers are in sync... I got the status data into a nested array, I would like to search key of each array and if "OK" is NOT present, echo other key=>values in the current array to a variable so...eg...let take the single array... (1 Reply)
Discussion started by: zeekblack
1 Replies

5. Shell Programming and Scripting

perl, put one array into many array when field is equal to sth

Hi Everyone, #!/usr/bin/perl use strict; use warnings; my @test=("a;b;qqq;c;d","a;b;ggg;c;d","a;b;qqq;c;d"); would like to split the @test array into two array: @test1=(("a;b;qqq;c;d","a;b;qqq;c;d"); and @test2=("a;b;ggg;c;d"); means search for 3rd filed. Thanks find the... (0 Replies)
Discussion started by: jimmy_y
0 Replies

6. Shell Programming and Scripting

PERL : Read an array and write to another array with intial string pattern checks

I have an array and two variables as below, I need to check if $datevar is present in $filename. If so, i need to replace $filename with the values in the array. I need the output inside an ARRAY How can this be done. Any help will be appreciated. Thanks in advance. (2 Replies)
Discussion started by: irudayaraj
2 Replies

7. Shell Programming and Scripting

Bash 3.2 - Array / Regex - IF 3rd member in array ends in 5 digits then do somthing...

Trying to do some control flow parsing based on the index postion of an array member. Here is the pseudo code I am trying to write in (preferably in pure bash) where possible. I am thinking regex with do the trick, but need a little help. pesudo code if == ENDSINFIVEINTS ]]; then do... (4 Replies)
Discussion started by: briandanielz
4 Replies

8. Shell Programming and Scripting

Bash arrays: rebin/interpolate smaller array to large array

hello, i need a bit of help on how to do this effectively in bash without a lot of extra looping or massive switch/case i have a long array of M elements and a short array of N elements, so M > N always. M is not a multiple of N. for case 1, I want to stretch N to fit M arrayHuge H = (... (2 Replies)
Discussion started by: f77hack
2 Replies

9. UNIX for Beginners Questions & Answers

Scanning array for partial elements in Bash Script

Example of problem: computerhand=(6H 2C JC QS 9D 3H 8H 4D) topcard=6D How do you search ${computerhand} for all elements containing either a "6" or a "D" then save the output to a file? This is a part of a Terminal game of Crazy 8's that I'm attempting to write in Bash. Any... (2 Replies)
Discussion started by: cogiz
2 Replies

10. UNIX for Beginners Questions & Answers

Inaccurate scanning of Bash array elements

username=cogiz #!/bin/bash shuffle() #@ USAGE: shuffle { #@ TODO: add options for multiple or partial decks Deck=$( printf "%s\n" {2,3,4,5,6,7,8,9,T,J,Q,K,A}{H,S,D,C} | awk '## Seed the random number generator BEGIN { srand() } ## Put a random number in front... (4 Replies)
Discussion started by: cogiz
4 Replies
GLPRIMITIVERESTARTIN(3G)					    OpenGL 3.3						  GLPRIMITIVERESTARTIN(3G)

NAME
glPrimitiveRestartIndex - specify the primitive restart index C SPECIFICATION
void glPrimitiveRestartIndex(GLuint index); PARAMETERS
index Specifies the value to be interpreted as the primitive restart index. DESCRIPTION
glPrimitiveRestartIndex specifies a vertex array element that is treated specially when primitive restarting is enabled. This is known as the primitive restart index. When one of the Draw* commands transfers a set of generic attribute array elements to the GL, if the index within the vertex arrays corresponding to that set is equal to the primitive restart index, then the GL does not process those elements as a vertex. Instead, it is as if the drawing command ended with the immediately preceding transfer, and another drawing command is immediately started with the same parameters, but only transferring the immediately following element through the end of the originally specified elements. When either glDrawElementsBaseVertex(), glDrawElementsInstancedBaseVertex() or glMultiDrawElementsBaseVertex() is used, the primitive restart comparison occurs before the basevertex offset is added to the array index. NOTES
glPrimitiveRestartIndex is available only if the GL version is 3.1 or greater. SEE ALSO
glDrawArrays(), glDrawElements(), glDrawElementsBaseVertex(), glDrawElementsInstancedBaseVertex() COPYRIGHT
Copyright (C) 2010 Khronos Group. This material may be distributed subject to the terms and conditions set forth in the Open Publication License, v 1.0, 8 June 1999. http://opencontent.org/openpub/. OpenGL 3.3 03/08/2011 GLPRIMITIVERESTARTIN(3G)
All times are GMT -4. The time now is 02:29 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy