The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Not able to read unique values in array faiz1985 Shell Programming and Scripting 1 09-08-2009 11:45 PM
Read textfile and enter the values in array luna_soleil Shell Programming and Scripting 3 02-25-2009 02:51 AM
how to read a var value into array aoussenko Shell Programming and Scripting 7 07-24-2008 11:35 PM
Read csv into Hash array? kinmak Shell Programming and Scripting 1 05-07-2008 11:35 AM
How to read from txt file and use that as an array pinky UNIX for Dummies Questions & Answers 4 10-08-2007 01:18 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 09-28-2009
Dedalus Dedalus is offline
Registered User
  
 

Join Date: May 2009
Location: Italy/France
Posts: 60
Read array from a file

Hi

I've a config file like:

file1

Code:
#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):

Code:
k_array2=$(awk '{ for (x = 1; x <= NF; x++) 

arr[x,NR]=$x; 
}
{ if (arr[1,NR] == "k_array:") {
    for(j=2;j<=NF;j++)
        k_array[j-1]=$j;
            
    }
} END{ for(j=1;j<=length(k_array);j++) print k_array[j]}' config_file)

but in this way the returned k_array seems to be a single element array.
In fact with


Code:
echo ${k_array2[0]}

I get ------> 1 2 3 4 5.

Any help?

Thanks

D.
 

Bookmarks

Tags
array, read file

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:36 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0