Prase a file and stored the result to an array


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Prase a file and stored the result to an array
# 1  
Old 09-03-2008
Prase a file and stored the result to an array

Dear all ,

I have a file whose content has the following format:

jboss.web:type=ThreadPool,name=AAAA
jboss.web:type=ThreadPool,name=BBBB

How can I parse this file to get the value of the name of each line (AAAA , BBBB) and store the result to an array ? (array[0] = AAAA , array[1] = BBBB).
Different files will have different total number of lines.

Regards.
# 2  
Old 09-03-2008
What programming language you are using?
# 3  
Old 09-03-2008
You can do something like:

Code:
#!/bin/sh

cnt=0

awk -F"=" '{print$3}' file | while read name
do
  arr[$cnt]=$name
  let cnt=cnt+1
done

Regards
# 4  
Old 09-03-2008
code:
sed -e 's/'^.*='/ /g' filename |awk '{print NR ,$1}'
or
sed -e 's/'^.*='/ /g' filename

this helps u. use in ur for loop
# 5  
Old 09-03-2008
Try using the below in a loop to assign in an array:

Code:
sed 's/\(.*\)name=\(.*\)/\2/' file

or

Code:
while read line; do echo ${line#jboss.web:type=ThreadPool,name=}; done<file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search if file exists for a file pattern stored in array

Hi experts, I have two arrays one has the file paths to be searched in , and the other has the files to be serached.For eg searchfile.dat will have abc303 xyz123 i have to search for files that could be abc303*.dat or for that matter any extension . abc303*.dat.gz The following code... (2 Replies)
Discussion started by: 100bees
2 Replies

2. Shell Programming and Scripting

ksh : Building an array based on condition result

I want to build an Errorlog. I would like to build an array as I move through the if statements and print the array once all error conditions have been defined. The results need to be comma delimited. tsver will be static "1.9.6(2)" other vars $prit $lt $rt can have the same or a different... (1 Reply)
Discussion started by: popeye
1 Replies

3. Shell Programming and Scripting

how to output the array result into a matrix

I have a file like this: ASSPASVFETQY,hTRBV12-4,hTRBJ2-5,2 ASSPASTGGDYGYT,hTRBV18,hTRBJ1-2,2 ASSPASGDGYT,hTRBV5-1,hTRBJ1-2,2 ASSPASFPEDTQY,hTRBV27,hTRBJ2-3,2 ASSPARVNYGYT,hTRBV5-1,hTRBJ1-2,2 ASSPARTSGGLNEQF,hTRBV6-4,hTRBJ2-1,2 ASSPARQSYNEQF,hTRBV11-1,hTRBJ2-1,2... (3 Replies)
Discussion started by: xshang
3 Replies

4. Shell Programming and Scripting

Assign zero to strings that don't appear in block, store result in AWK array

Hi to all, I have this input: <group> <x "2">Group D</x> <x "3">Group B</x> <x "1">Group A</x> </group> <group> <x "1">Group E</x> <x "0">Group B</x> <x "1">Group C</x> </group> <group> ... (11 Replies)
Discussion started by: Ophiuchus
11 Replies

5. Shell Programming and Scripting

how can I check the first character of each variable stored in array

variables are stored in this format D0000, D12345, S1234, D12345 | KestrelPrdV2_0.build.177 - svn 141115 tag as V2.0.0.14 D0000, D12345, S1234, D12345 My question is how can I check the first character of each variable stored in array.It should be start with D or S. Please help... (7 Replies)
Discussion started by: anuragpgtgerman
7 Replies

6. Shell Programming and Scripting

How to put db2 query result into an array in shell script?

Hello, Can someone please advise me how to put the db2 query reult into an array? For example, the query reults are: string A string B string C Then how do I put them into array=string A array=string B ... (2 Replies)
Discussion started by: hanul
2 Replies

7. Shell Programming and Scripting

Result set into an array

Hi, I have an issue with the result set. I wanted to run db2 query against db2 server in unix environment using perl script. I wanted to get the result set into an array. $db=<<DB_Name>> connect to $db get connection state this is my query = SELECT DISTINCT 'R' FROM... (0 Replies)
Discussion started by: solo123
0 Replies

8. Shell Programming and Scripting

Prase a file and store and result to an array

Dear all, I have a file having the following formats: ThreadFail=Web1=1234 ThreadFail=Web2=2345 ThreadFail=Web3=12 ConnectionFail=DB1=11 ConnectionFail=DB2=22 The number of lines will be different from every time . How can I parse the file and store the result to an a array inside... (6 Replies)
Discussion started by: youareapkman
6 Replies

9. Shell Programming and Scripting

Outputting formatted Result log file from old 30000 lines result log<help required>

Well I have a 3000 lines result log file that contains all the machine data when it does the testing... It has 3 different section that i am intrsted in 1) starting with "20071126 11:11:11 Machine Header 1" 1000 lines... "End machine header 1" 2) starting with "20071126 12:12:12 Machine... (5 Replies)
Discussion started by: vikas.iet
5 Replies

10. Shell Programming and Scripting

How to store query multiple result in shell script variable(Array)

:) Suppose,I have one table A. Table A have one column. Table A have 10 rows. I want this 10 rows store into shell script variable. like #!/bin/ksh v_shell_var=Hi here in call oracle , through loop How can I store table A's 10 rows into v_shell_var (Shell Script Array). Regards, Div (4 Replies)
Discussion started by: div_Neev
4 Replies
Login or Register to Ask a Question