problem to read data in array


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting problem to read data in array
# 8  
Old 12-11-2009
something like
Code:
#!/bin/bash
while read L1
do
    if [ "${L1:0:1}" = "#" ]
    then
        read L2
        /statistic_program $L1 $L2
done < input.txt

# 9  
Old 12-11-2009
Thanks frans,
Can I ask you what is the meaning of the (L1:0:1) and L1,L2 represent inside your code?
Thanks ya Smilie

---------- Post updated at 06:11 AM ---------- Previous update was at 06:11 AM ----------

Thanks frans,
Can I ask you what is the meaning of the (L1:0:1) and L1,L2 represent inside your code?
Thanks ya Smilie
# 10  
Old 12-11-2009
Code:
#!/bin/bash
while read L1 # reads the current line and stores it in L1
do
    if [ "${L1:0:1}" = "#" ] # gives the first character of curent line
    then
    read L2 # reads the next line ans stores it in L2
    /statistic_program $L1 $L2 # runs the program with the values of L1 and L2 as parameters
done < input.txt

# 11  
Old 12-11-2009
Hi frans,
I just try your code.
But it won't work Smilie
It appears the message like this :
syntax error near unexpected token 'done'
# 12  
Old 12-11-2009
apologize, i forgot the fi in if then fi statement !!
Code:
#!/bin/bash
while read L1
do
    if [ "${L1:0:1}" = "#" ]
    then
        read L2
        /statistic_program $L1 $L2
    fi
done < input.txt

# 13  
Old 12-11-2009
Hi frans,
Thanks for your help and advice.
I very appreciate it Smilie
Unfortunately, the code that you suggested still can't take the query sequence continuously read the query one by one Smilie
Generally, the statistic_program will take this format as their input file:
Code:
#read_1
123456898787987

"#" represents the sequence_header, while the "123456898787987" is the content of the #read_1 that the "statistics_program" will deal with it each times.
sorry if my problem confusing you Smilie
# 14  
Old 12-11-2009
So, you don't need the header?
Code:
#!/bin/bash
I=0
while read L1
do
    if [ "${L1:0:1}" = "#" ]
    then
        read L2
        DATA[$I]=$L2
        (( I++ ))
    fi
done < input.txt
/statistic_program ${DATA[@]}


Last edited by frans; 12-11-2009 at 07:56 AM.. Reason: wrong argument
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