Sponsored Content
Full Discussion: remove an element from array
Top Forums Shell Programming and Scripting remove an element from array Post 302449637 by zaxxon on Tuesday 31st of August 2010 05:11:55 AM
Old 08-31-2010
The way you declare the array, you only have 1 element in it - you have to leave the double quotation marks away.

There is no functions available to delete elements directly from an array in ksh. You can either set it in a case of a match while looping (I did it without using it's index but treating it as a list) through the elements to "nothing" but you will have a gap in the array then. If you want to remove it and have the array elements filling up the gap, you can try something like this:

Code:
> set -A TABLENAME mirf roxar keke mirs
> echo ${TABLENAME[2]}
keke
> TMP=$(for A in ${TABLENAME[*]}; do echo $A| grep -v keke; done)
> echo $TMP     ## at this stage, TMP is no array since it's elements have no index, so we will make an array of it again with set -A 2 lines below:
mirf roxar mirs
> set -A TABLENAME $(echo $TMP)
> echo ${TABLENAME[2]}
mirs

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

accessing my first element of array

Hello everyonel, I have an array set like so num=4 read name arr=name I go through while loop to assign different values to different array element from 1 to 4. when I try to access the FIRST element of the array I get the last one first. Like if I say ${arr} it will show the last element... (4 Replies)
Discussion started by: afadaghi
4 Replies

2. Shell Programming and Scripting

Perl delete an element from array

Probably I am not seeing it or I am not using the "delete" correctly I had the following codes but it does not work for me #!/bin/perl -w ... @sysFile1 = (a_b, a_c, a_d); @sysFile2 = (a_c, a_e, b_f); foreach $line1 (@sysFile1){ trim(\$line1); (my $tmp1, my $tmp2) = split/_/,... (6 Replies)
Discussion started by: ahtat99
6 Replies

3. Shell Programming and Scripting

Remove an element from an array in PERL

Hello guys, I have the following question. Consider the following code in PERL for($xeAnumber=0; $xeAnumber<@xeAnumber; $xeAnumber++) { if(@xeAnumber==@final_file) { @final_file=@xeTimeStamp; }... (3 Replies)
Discussion started by: chriss_58
3 Replies

4. Shell Programming and Scripting

Adding array element in KSH

All, I would like to add the first 10 elements of an array. Here is how I am doing it now (only included first few add ops): #!/usr/bin/ksh ###Grab the array values out of a file### TOTAL=`awk '/time/' /tmp/file.out | awk '{print $4}'` set -A times $TOTAL SUM=$((${times} + times... (3 Replies)
Discussion started by: Shoeless_Mike
3 Replies

5. Shell Programming and Scripting

Shift array element

I want to delete and 0th element of array in shell scrpit and also shift all others to one level up. (2 Replies)
Discussion started by: darshakraut
2 Replies

6. Programming

how to put element of an array to first position.

hi, I have a array like my $array = ( "apple","ball","cat","dog","elephant"); how to push some element in the array to the first position. for example my final array should be elephant apple ball cat dog (5 Replies)
Discussion started by: vprasads
5 Replies

7. Shell Programming and Scripting

Multiplying array element

I am trying to take all the elements of an array and multiply them by 2, and then copy them to a new array. Here is what I have i=0 for true in DMGLIST do let DMGSIZES2="${DMGSIZES}"*2 let i++ done unset i echo ${DMGSIZES2} It does the calculation correctly for the first element,... (7 Replies)
Discussion started by: nextyoyoma
7 Replies

8. Shell Programming and Scripting

Filter output as an array element

I am filtering the value of Server status from a file and am storing it in a temp file which I compare later to exit with appropriate status. I am wondering if I can directly output the value of Server status as an array element and then compare the value of elements to get the right exit status ... (2 Replies)
Discussion started by: paslas
2 Replies

9. Shell Programming and Scripting

How to insert an array element within regex?

Hello to all, I'm trying to separate the string "str" using a regex within match function. The substrings that I want to separate, begin with 22, 23, 24 or 25 and followed by 12 or 14 characters. And I want to replace 22 with MJS, 23 with UYT, 24 with WER and 25 with PIL. For this string... (4 Replies)
Discussion started by: Ophiuchus
4 Replies

10. UNIX for Advanced & Expert Users

Array Element

This question is for someone that's more familiar with Array Element. I need to know if the maximum array element that can be assigned is 1024 and if its so, Is there a workaround solution when the counter exceeded 1024? param_array="$param_nam" counter=$counter+1 #to avoid space... (3 Replies)
Discussion started by: cumeh1624
3 Replies
COUNT(3)								 1								  COUNT(3)

count - Count all elements in an array, or something in an object

SYNOPSIS
int count (mixed $array_or_countable, [int $mode = COUNT_NORMAL]) DESCRIPTION
Counts all elements in an array, or something in an object. For objects, if you have SPL installed, you can hook into count(3) by implementing interface Countable. The interface has exactly one method, Countable::count, which returns the return value for the count(3) function. Please see the Array section of the manual for a detailed explanation of how arrays are implemented and used in PHP. PARAMETERS
o $array_or_countable - An array or Countable object. o $mode - If the optional $mode parameter is set to COUNT_RECURSIVE (or 1), count(3) will recursively count the array. This is particu- larly useful for counting all the elements of a multidimensional array. Caution count(3) can detect recursion to avoid an infinite loop, but will emit an E_WARNING every time it does (in case the array contains itself more than once) and return a count higher than may be expected. RETURN VALUES
Returns the number of elements in $array_or_countable. If the parameter is not an array or not an object with implemented Countable inter- face, 1 will be returned. There is one exception, if $array_or_countable is NULL, 0 will be returned. Caution count(3) may return 0 for a variable that isn't set, but it may also return 0 for a variable that has been initialized with an empty array. Use isset(3) to test if a variable is set. EXAMPLES
Example #1 count(3) example <?php $a[0] = 1; $a[1] = 3; $a[2] = 5; $result = count($a); // $result == 3 $b[0] = 7; $b[5] = 9; $b[10] = 11; $result = count($b); // $result == 3 $result = count(null); // $result == 0 $result = count(false); // $result == 1 ?> Example #2 Recursive count(3) example <?php $food = array('fruits' => array('orange', 'banana', 'apple'), 'veggie' => array('carrot', 'collard', 'pea')); // recursive count echo count($food, COUNT_RECURSIVE); // output 8 // normal count echo count($food); // output 2 ?> SEE ALSO
is_array(3), isset(3), strlen(3). PHP Documentation Group COUNT(3)
All times are GMT -4. The time now is 06:17 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy