Sponsored Content
Top Forums Shell Programming and Scripting Array Count and Array Copy help Post 302838993 by RavinderSingh13 on Wednesday 31st of July 2013 05:13:21 AM
Old 07-31-2013
Hello,

For counting the number of elements in an array as per your exampple. Please try the following. Kindly let me know in case you have queries.


Code:
$ cat array_count.ksh
fileStreamLoad=""ab.csv","bc.csv","cd.csv","de.csv","ef.csv","fg.csv"";
j=0
value_fileStreamLoad=`echo $fileStreamLoad | sed 's/,/ /g; s/\"//g'`
set -A array_fileStreamLoad ${value_fileStreamLoad}
echo ${array_fileStreamLoad[@]}

for  a in ${array_fileStreamLoad[@]}
do
let "j = j +1"

done

echo $j



Output for this script is as follows.


Code:
$ ksh array_count.ksh
ab.csv bc.csv cd.csv de.csv ef.csv fg.csv
6
$



Note: You can comment the bold line in comment if you don't want to show array's elements.





Thanks,
R. Singh
 

10 More Discussions You Might Find Interesting

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

2. UNIX for Advanced & Expert Users

Array copy in ksh

Hi all, Following code in ksh is giving error: fileLimit=5 func(){ dir="$1" format="$2" array="$3" i=0 ls -lrt $format | tail -${fileLimit} | while read f_det; do files="${f_det}," ((i+=1)) done eval $(echo set -A $array '"${files}"') } func "." "*.pl" "a" echo... (10 Replies)
Discussion started by: PRKS
10 Replies

3. Shell Programming and Scripting

Beginner: Count & Sort Using Array's

Hi, I'm new to linux & bash so please forgive my ignorance, just wondering if anyone can help. I have a file (mainfile.txt) with comma deliminated values, like so: $1 $2 $3 613212, 36, 57 613212, 36, 10 613212, 36, 10 677774, 36, 57 619900, 10, 10 i need to split this file... (12 Replies)
Discussion started by: BigTOE
12 Replies

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

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

6. Programming

Array[count+1] legal?

I get weird decimal digits when I run the program below. int coe_amount; cout << "How many coefficients exist in your term? "; cin >> coe_amount; float coefficient; for (int count = 0; count < coe_amount; count ++) { ... (4 Replies)
Discussion started by: DyslexicChciken
4 Replies

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

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

9. Shell Programming and Scripting

Count number of unique values in each column of array

What is an efficient way of counting the number of unique values in a 400 column by 1000 row array and outputting the counts per column, assuming the unique values in the array are: A, B, C, D In other words the output should look like: Value COL1 COL2 COL3 A 50 51 52... (16 Replies)
Discussion started by: Geneanalyst
16 Replies

10. Shell Programming and Scripting

Copy of array by index value fails

Hello, I have a complicated situational find and replace that I wrote in bash because I didn't know how to do everything in awk. The code works but is very slow, as expected. To create my modified file, I am looping through an array that was populated earlier and making some replacements at... (6 Replies)
Discussion started by: LMHmedchem
6 Replies
ENCHANT_BROKER_LIST_DICTS(3)						 1					      ENCHANT_BROKER_LIST_DICTS(3)

enchant_broker_list_dicts - Returns a list of available dictionaries

SYNOPSIS
mixed enchant_broker_list_dicts (resource $broker) DESCRIPTION
Returns a list of available dictionaries with their details. PARAMETERS
o $broker - Broker resource RETURN VALUES
Returns TRUE on success or FALSE on failure. EXAMPLES
Example #1 List all available dictionaries for one broker <?php $r = enchant_broker_init(); $dicts = enchant_broker_list_dicts($r); print_r($dicts); ?> The above example will output something similar to: Array ( [0] => Array ( [lang_tag] => de [provider_name] => aspell [provider_desc] => Aspell Provider [provider_file] => /usr/lib/enchant/libenchant_aspell.so ) [1] => Array ( [lang_tag] => de_DE [provider_name] => aspell [provider_desc] => Aspell Provider [provider_file] => /usr/lib/enchant/libenchant_aspell.so ) [3] => Array ( [lang_tag] => en [provider_name] => aspell [provider_desc] => Aspell Provider [provider_file] => /usr/lib/enchant/libenchant_aspell.so ) [4] => Array ( [lang_tag] => en_GB [provider_name] => aspell [provider_desc] => Aspell Provider [provider_file] => /usr/lib/enchant/libenchant_aspell.so ) [5] => Array ( [lang_tag] => en_US [provider_name] => aspell [provider_desc] => Aspell Provider [provider_file] => /usr/lib/enchant/libenchant_aspell.so ) [6] => Array ( [lang_tag] => hi_IN [provider_name] => myspell [provider_desc] => Myspell Provider [provider_file] => /usr/lib/enchant/libenchant_myspell.so ) ) SEE ALSO
enchant_broker_describe(3). PHP Documentation Group ENCHANT_BROKER_LIST_DICTS(3)
All times are GMT -4. The time now is 04:51 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy