![]() |
|
|
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 |
| Reading a file line by line and processing for each line | sagarparadkar | Shell Programming and Scripting | 6 | 03-02-2009 11:59 AM |
| Problem with reading file line-by-line, and outputting to a new file | Darkness Fish | Shell Programming and Scripting | 4 | 07-18-2008 07:54 AM |
| reading text file line by line | MizzGail | Shell Programming and Scripting | 6 | 04-14-2008 07:58 AM |
| Ksh Storing Multiple Files and reading each line in each file. | developncode | UNIX for Dummies Questions & Answers | 1 | 04-08-2008 05:44 PM |
| Reading Multiple Variables From a Single Line in Shell | Drek | Shell Programming and Scripting | 14 | 12-21-2006 11:20 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
KSH: Reading a file line by line into multiple arrays
Hi -
I have a file that contains data in this format:- #comment value1 value2 value3 #comment value4 value5 value6 value7 #comment value8 value9 I need to read value1, value2 and value3 into one array, value4 value5 value6 and value7 into another array and value8 and value9 into a 3rd array. If necessary I could prefix each line with the name of the array .... e.g. array_name1 value1 value2 value3 I would be grateful if someone please tell me the best way of doing this? I don't need to necessarily create arrays either - I just need to get the values into my script to be used in various do .. while loops. I could just create the arrays in the script and be done with but I am not sure this is the best way of doing things. Thanks for your help. |
|
||||
|
Thanks for the suggestion ... I have tried :-
while read line ; do read line1 set -A arr $line1 done < /tmp/test.txt and also i=0 exec < /tmp/test.txt while read line ; do arr[i]=$line echo ${arr[i]} (( i=i+1 )) done What I actually need to do though is read each line into a separate array. e.g. /tmp/test.txt contains :- # some comment one two three four # some comment five six seven So I need an array containing the values one two three and four and a separate array containing the values five six and seven. Is this even possible ? Thanks for the help. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|