problem to read data in array


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting problem to read data in array
# 1  
Old 12-11-2009
problem to read data in array

My input is a long list of data start with "#":
Code:
#read_1
123456898787987

#read_2
54645646540646406

#read_3
4654564654316
.
.

I got a bit confusing about how to set all in an array first. And then when I run a program name "statistic_program", it will read the array in scalar and do it one by one continuously.
I got think to use "While Read Array Do Done", just I not sure how to let the "statistic_program", run the input file data one by one.
Below is the perl script that I just try.
Code:
#!/usr/bin/perl
use strict;
use warnings;
open(FILE,"<INPUT_FILE.txt");
my($file)=<FILE>;
my@lines=split('#',$file);
foreach my $data (@lines){
system "/statistic_program $data >> output.txt"}
exit 0;

Unfortunately, the perl script can't work nice as well Smilie
Thanks for any suggestion and advice.

Last edited by patrick87; 12-11-2009 at 06:04 AM..
# 2  
Old 12-11-2009
Can't the "statistic_program" directly read the input file?
# 3  
Old 12-11-2009
Hi frans,
The "statistic_program" only allow to read one sequence each time and give one output.
For example, if my input file got 20 read, I need to repeat do it 20 times and will generate 20 output file. It is very bad Smilie
I try to write a script to let the "statistic_program" continuously run each sequence and generate only one output file instead of 20 output file at the end.
Unfortunately, I facing some problem to write the script.
Thus I ask from all of your advice and suggestion.
Thanks first Smilie
# 4  
Old 12-11-2009
Could you give an example of the desired output (is it only the numbers under the #read_N statement? should the 'N' be the index in the array?)
# 5  
Old 12-11-2009
After running the "statistic_program" , it will generate a list of statistic detail about each query sequence. Thus hopefully all the input file run using the "statistic_program".
I only can try to write a script to allow each sequence continuously run one by one by "statistic_program" because I can't edit the statistic_program as well because it is at binary mode Smilie
Thanks for your advice Smilie
# 6  
Old 12-11-2009
It's not what i meant. what is the needed format for input of that binary program?
# 7  
Old 12-11-2009
The input format for the binary program just like the input file sequence that I have shown:
Code:
#read_1
123456898787987

But the program only able to run one sequence each times so far. Thus need to write a script to let the input file data take like an array to automatic run now.
All the data query sequence beginning with "#"
Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

In PErl script: need to read the data one file and generate multiple files based on the data

We have the data looks like below in a log file. I want to generat files based on the string between two hash(#) symbol like below Source: #ext1#test1.tale2 drop #ext1#test11.tale21 drop #ext1#test123.tale21 drop #ext2#test1.tale21 drop #ext2#test12.tale21 drop #ext3#test11.tale21 drop... (5 Replies)
Discussion started by: Sanjeev G
5 Replies

2. Programming

C++ how would you read this file into an array.

here is the pesudo file. REREREEEEEERRRREER SOMEStrinG1234 RERRRR EEERRRREER SOMEStrinG1224 REREREEEREERRR REE SOMEStrinG1214 REREREREREREREEEER SOMEStrinG1204 RERE EEEEEERRRRRRR SOMEStrinG1294 REREEREEE ERRRREER SOMEStrinG1284 REREREEEEEERR REER here is my attempted code #include... (3 Replies)
Discussion started by: briandanielz
3 Replies

3. Shell Programming and Scripting

Read file and get the data then put it in array

Hi, I have a file called "readfile" it contains below parameters #cat readfile word=/abc=225,/abc/cba=150 three=12 four=45 five=/xyz/yza likewise multiple line. From the above file, I have to read "word" output should be like, /abc /abc/cba these values need to be put in... (3 Replies)
Discussion started by: munna_dude
3 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

Array; while read line do problem

Hi - I don't understand why the following script isn't working. I want to read the contents of a while loop into an array, but it looks like the array is destroyed once the while loop is finished. Can anybody help? someFile: PC_1 wf_test1 Test PC_2 wf_test2 Test PC_3 wf_test3 Test Script:... (3 Replies)
Discussion started by: lt1776
3 Replies

6. Programming

Problem with read data from serial device

I have problem with C programming. I want to send & receive data through serial communication. I send data(command) to device to get data from device but when receive data, it can't get altogether of data. It get only some data. What should I do to get altogether of data? If all of... (7 Replies)
Discussion started by: noppon_s
7 Replies

7. AIX

Tape drive problem - no process to read data written to a pipe

Hi Everyone, The machine I'm working on is an AIX 5.3 LPAR running on a P650. oslevel -r shows 5300-08. I'm trying to take a backup to a SCSI tape drive, which has been working up until this point. I know of nothing that has changed recently to cause this problem. But when I try to take a... (0 Replies)
Discussion started by: need2bageek
0 Replies

8. Shell Programming and Scripting

Read array from a file

Hi I've a config file like: file1 #comment k_array: 1 2 3 4 5 n_array: 7 8 9 0 11 I'd like to write a script that read it and store k_array and n_array in 2 arrays. I mean the script should be able to use both as array. I've tried to use awk as (only for one array): ... (5 Replies)
Discussion started by: Dedalus
5 Replies

9. Shell Programming and Scripting

how to read a var value into array

Hi I need to read a value of the variable into array so each character/digit will become an array element,for example: A=147921231432545436547568678679870 The resulting array should hold each digit as an element. Thanks a lot for any help -A (7 Replies)
Discussion started by: aoussenko
7 Replies

10. UNIX for Advanced & Expert Users

how to read the data from an excel sheet and use those data as variable in the unix c

I have 3 columns in an excel sheet. c1 c2 c3 EIP_ACCOUNT SMALL_TS_01 select A.* from acc; All the above 3 col shoud be passed a variable in the unix code. 1.How to read an excel file 2.How to pass these data as variable to the unic script (1 Reply)
Discussion started by: Anne Grace
1 Replies
Login or Register to Ask a Question