![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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 |
| Display Modes | Rate This Thread |
|
|