Sponsored Content
Top Forums Shell Programming and Scripting Bash arrays: rebin/interpolate smaller array to large array Post 302966575 by f77hack on Saturday 13th of February 2016 04:34:45 PM
Old 02-13-2016
Quote:
Originally Posted by RudiC
Not too clear what you expect. How about
Code:
S=(0 1 2 3)
H=(A B C D E F G H I J K)
while [ ${#SX[@]} -lt ${#H[@]} ]; do SX=(${SX[@]} ${S[@]}); done
for ((i=${#H[@]}; i<=${#SX[@]}; i++)); do unset SX[$i]; done
echo ${SX[@]}, ${#SX[@]}, ${!SX[@]}, ${H[@]} 
0 1 2 3 0 1 2 3 0 1 2, 11, 0 1 2 3 4 5 6 7 8 9 10, A B C D E F G H I J K

Great. Didn't think of wrapping the small array like that. I knew someone would come up with good compact code. Thanks!

This is what I was looking for

Code:
while [ ${#SX[@]} -lt ${#H[@]} ]; do SX=(${SX[@]} ${S[@]}); done


Last edited by f77hack; 02-13-2016 at 05:52 PM.. Reason: added code
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl array of arrays

Hi, I am trying to assign an array as a value to one of the array element, I mean I have an array @KS and array @kr. I want array @KS to hold @kr as an element. So I am doin this $KS=@kr; But the value stored is number of elements in the @kr array. Can... (2 Replies)
Discussion started by: eamani_sun
2 Replies

2. Shell Programming and Scripting

Searching array of arrays in perl

Suppose there are two arrays of arrays: @A = ( , , , ); @B = ( , , , , ); For each of $A, $A, $A..., I want to find the corresponding one in @B (match the letter, like $A eq $B), and print out both the second item, for example, $A and $B. How can I do this in perl? grep + map? Hope I... (1 Reply)
Discussion started by: zx1106
1 Replies

3. Shell Programming and Scripting

PHP arrays as array elements

PHP question...I posted this on the Web Development forum, but maybe this is a better place! I have an SQL query that's pulled back user IDs as a set of columns. Rather than IDs, I want to use their names. So I have an array of columns $col with values 1,7,3,12 etc and I've got an array $person... (3 Replies)
Discussion started by: JerryHone
3 Replies

4. Shell Programming and Scripting

perl - need help with 2 arrays to hash or 2d array?

I have 2 arrays: @array1 outputs the following: 1 1 1 2 @array2 outputs the following A B C D (2 Replies)
Discussion started by: streetfighter2
2 Replies

5. Shell Programming and Scripting

using arrays and also help with array.contains functionality

here is what i have... i=1 while read line do if grep -i-q "create procedure"<<<$line then startline="$line" endline="blahblah" Get procedure name into a variable named procName procName="procedure name is stored" do some... (2 Replies)
Discussion started by: vivek d r
2 Replies

6. 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

7. Shell Programming and Scripting

Bash Array connectin to another Array

Hello, i have a script that i need account_number to match a name. for exsample : ACCOUNT_ID=(IatHG8DC7mZbdymSoOr11w KbnlG2j-KRQ0-1_Xk356s8) and i run a loop curl requst with this the issue is that i want to know on which account were talking about so bash will know this : ... (4 Replies)
Discussion started by: batchenr
4 Replies

8. Programming

Making an array of 2D arrays in C

I hate I'm asking for help again. Unfortunately it seems there just aren't any links I can find on making an array that holds a bunch of two dimensional arrays. Maybe my google-fu is lacking. Basically I have a header file like this: #define MATRIX 10 int white_l1; int white_l2; int... (2 Replies)
Discussion started by: Azrael
2 Replies

9. Programming

Calling an array of arrays in C.

Corona688 was great in helping me learn how to create arrays that hold other two dimensional array here. Unfortunately I didn't think ask about how to implement or call them. Basically, I'm trying to call an array of two-dimensional arrays like this: declaration: int (*side_one) = { { white_l1,... (6 Replies)
Discussion started by: Azrael
6 Replies

10. Programming

Looping an array of 2d arrays in C

Le sigh... Hopefully this will be the last time I have to ask for help on this topic. For a while now I've been working with a 1d array that holds 2d arrays. For reference you can view here. Now I'm just trying to loop through the elements with the following: #include <stdio.h> void... (3 Replies)
Discussion started by: Azrael
3 Replies
ARRAY_REPLACE_RECURSIVE(3)						 1						ARRAY_REPLACE_RECURSIVE(3)

array_replace_recursive - Replaces elements from passed arrays into the first array recursively

SYNOPSIS
array array_replace_recursive (array $array1, array $array2, [array $...]) DESCRIPTION
array_replace_recursive(3) replaces the values of $array1 with the same values from all the following arrays. If a key from the first array exists in the second array, its value will be replaced by the value from the second array. If the key exists in the second array, and not the first, it will be created in the first array. If a key only exists in the first array, it will be left as is. If several arrays are passed for replacement, they will be processed in order, the later array overwriting the previous values. array_replace_recursive(3) is recursive : it will recurse into arrays and apply the same process to the inner value. When the value in $array1 is scalar, it will be replaced by the value in $array2, may it be scalar or array. When the value in $array1 and $array2 are both arrays, array_replace_recursive(3) will replace their respective value recursively. PARAMETERS
o $array1 - The array in which elements are replaced. o $array2 - The array from which elements will be extracted. o $... - Optional. More arrays from which elements will be extracted. RETURN VALUES
Returns an array, or NULL if an error occurs. EXAMPLES
Example #1 array_replace_recursive(3) example <?php $base = array('citrus' => array( "orange") , 'berries' => array("blackberry", "raspberry"), ); $replacements = array('citrus' => array('pineapple'), 'berries' => array('blueberry')); $basket = array_replace_recursive($base, $replacements); print_r($basket); $basket = array_replace($base, $replacements); print_r($basket); ?> The above example will output: Array ( [citrus] => Array ( [0] => pineapple ) [berries] => Array ( [0] => blueberry [1] => raspberry ) ) Array ( [citrus] => Array ( [0] => pineapple ) [berries] => Array ( [0] => blueberry ) ) Example #2 array_replace_recursive(3) and recursive behavior <?php $base = array('citrus' => array("orange") , 'berries' => array("blackberry", "raspberry"), 'others' => 'banana' ); $replacements = array('citrus' => 'pineapple', 'berries' => array('blueberry'), 'others' => array('litchis')); $replacements2 = array('citrus' => array('pineapple'), 'berries' => array('blueberry'), 'others' => 'litchis'); $basket = array_replace_recursive($base, $replacements, $replacements2); print_r($basket); ?> The above example will output: Array ( [citrus] => Array ( [0] => pineapple ) [berries] => Array ( [0] => blueberry [1] => raspberry ) [others] => litchis ) SEE ALSO
array_replace(3), array_merge_recursive(3). PHP Documentation Group ARRAY_REPLACE_RECURSIVE(3)
All times are GMT -4. The time now is 02:24 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy