02-23-2010
how to spilit a row into fields and store the field content to the array
consider this is a line A#B#C#D#E#F#G#H
note the delimeter is #
i want to cut or spilt in to fields using the delimeter # and to store in an array.
like this
array[0]=A
array[1]=B
array[2]=C
array[3]=D
array[4]=E
and the array content should be displayed.
echo "${array[$0]}"
echo "${array[$1]}"
echo "${array[$2]}"
echo "${array[$3]}"
echo "${array[$4]}"
provide me code and i am using bash script.
Thanks
barani
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I need to split a long varible which is a whole line read from a file into fields and store them in an array, the fields are delimited by pipe and a field may contain white spaces.
I tried the following concept test and it has problem with field 5 which contain a space, appearently so because... (3 Replies)
Discussion started by: gratus
3 Replies
2. Shell Programming and Scripting
Hi,
I have a file that has data in it that says
00:01:48.233 1212
00:01:56.233 345
00:09:01.221 5678
00:12:23.321 93444
The file has more line than this but i just wanted to put in a snippet to ask how I would get the highest number with time stamp into another file. So from the above... (2 Replies)
Discussion started by: pat4519
2 Replies
3. Shell Programming and Scripting
Hi,
the csv file with the delimeter #.
A#B#C#D#E#F#G#H
1#2#3#4#5#6#7#8
Z#x#c#V
7#2#8#9
N.
I want to read the file line by line and store in rowarray.
then the rowarray content should be spilt or made to fields using the delimeter #.
i am not sure can we store the fields in to... (3 Replies)
Discussion started by: barani75
3 Replies
4. Shell Programming and Scripting
Hi
I want to write a script which store all the parameters passed to the script into an array.
Once it is stored I want scan through the array and and delete those files for last month present inside the directory. The files in directory is appneded with YYYY_MM_DD.
I want to know how can I... (3 Replies)
Discussion started by: dgmm
3 Replies
5. Shell Programming and Scripting
How to store the content from array to either "row-column" or "column-row" order? (0 Replies)
Discussion started by: kavi.mogu
0 Replies
6. Shell Programming and Scripting
hi,
i have a variable which contains some file names separated by comma. example
FNAME="abc.txt,def.txt,ghi.txt"
i want to extract each filename and store it into an array and also count the number of files in the array.
file=abc.txt
file=def.txt
file=ghi.txt
i thought of using the... (8 Replies)
Discussion started by: Little
8 Replies
7. Shell Programming and Scripting
Hi experts,
I need to print the first field first then last two fields should come next and then i need to print rest of the fields.
Input :
a1,abc,jsd,fhf,fkk,b1,b2
a2,acb,dfg,ghj,b3,c4
a3,djf,wdjg,fkg,dff,ggk,d4,d5
Expected output:
a1,b1,b2,abc,jsd,fhf,fkk... (6 Replies)
Discussion started by: 100bees
6 Replies
8. Shell Programming and Scripting
Hi All,
I have the input as below:
cat input
032016002 2.891 97.109 16.605 27.172 24.017 32.207 0.233 0.021 39.810 0.077 0.026 19.644 13.882 0.131 11.646 0.102 11.449 76.265 23.735 16.991 83.009 8.840 91.160 0.020 99.980 52.102 47.898 44.004 55.996 39.963 18.625 0.121 1.126 40.189... (15 Replies)
Discussion started by: am24
15 Replies
9. Shell Programming and Scripting
Hi ALL,
We have requirement in a file, i have multiple rows.
Example below:
Input file rows
01,1,102319,0,0,70,26,U,1,331,000000113200000011920000001212
01,1,102319,0,1,80,20,U,1,241,00000059420000006021
I need my output file should be as mentioned below. Last field should split for... (4 Replies)
Discussion started by: kotra
4 Replies
10. Shell Programming and Scripting
I have the following script that will average the last two fields of each row, but im not sure how to include the 3rd field of the following row.
An example of the analysis that I need to perform from the input - (66.61+58.01+54.16)/3
awk '{sum=cnt=0; for (i=13;i<=NF;i++) { sum+=$i; cnt++... (1 Reply)
Discussion started by: ncwxpanther
1 Replies
LEARN ABOUT PHP
splfixedarray
SPLFIXEDARRAY(3) 1 SPLFIXEDARRAY(3)
The SplFixedArray class
INTRODUCTION
The SplFixedArray class provides the main functionalities of array. The main differences between a SplFixedArray and a normal PHP array is
that the SplFixedArray is of fixed length and allows only integers within the range as indexes. The advantage is that it allows a faster
array implementation.
CLASS SYNOPSIS
SplFixedArray
SplFixedArrayIteratorArrayAccessCountable
Methods
o public SplFixedArray::__construct ([int $size])
o public int SplFixedArray::count (void )
o public mixed SplFixedArray::current (void )
o publicstatic SplFixedArray SplFixedArray::fromArray (array $array, [bool $save_indexes = true])
o public int SplFixedArray::getSize (void )
o public int SplFixedArray::key (void )
o public void SplFixedArray::next (void )
o public bool SplFixedArray::offsetExists (int $index)
o public mixed SplFixedArray::offsetGet (int $index)
o public void SplFixedArray::offsetSet (int $index, mixed $newval)
o public void SplFixedArray::offsetUnset (int $index)
o public void SplFixedArray::rewind (void )
o public int SplFixedArray::setSize (int $size)
o public array SplFixedArray::toArray (void )
o public bool SplFixedArray::valid (void )
o public void SplFixedArray::__wakeup (void )
EXAMPLES
Example #1
SplFixedArray usage example
<?php
// Initialize the array with a fixed length
$array = new SplFixedArray(5);
$array[1] = 2;
$array[4] = "foo";
var_dump($array[0]); // NULL
var_dump($array[1]); // int(2)
var_dump($array["4"]); // string(3) "foo"
// Increase the size of the array to 10
$array->setSize(10);
$array[9] = "asdf";
// Shrink the array to a size of 2
$array->setSize(2);
// The following lines throw a RuntimeException: Index invalid or out of range
try {
var_dump($array["non-numeric"]);
} catch(RuntimeException $re) {
echo "RuntimeException: ".$re->getMessage()."
";
}
try {
var_dump($array[-1]);
} catch(RuntimeException $re) {
echo "RuntimeException: ".$re->getMessage()."
";
}
try {
var_dump($array[5]);
} catch(RuntimeException $re) {
echo "RuntimeException: ".$re->getMessage()."
";
}
?>
The above example will output:
NULL
int(2)
string(3) "foo"
RuntimeException: Index invalid or out of range
RuntimeException: Index invalid or out of range
RuntimeException: Index invalid or out of range
PHP Documentation Group SPLFIXEDARRAY(3)