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
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

Closed Thread
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
  #1 (permalink)  
Old 06-08-2009
sniper57 sniper57 is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 17
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.
  #2 (permalink)  
Old 06-08-2009
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,423
the var line1 will have what you want.. use how ever you want

Code:
while read line ; do
read line1
echo "$line1"
done < filename

  #3 (permalink)  
Old 06-09-2009
sniper57 sniper57 is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 17
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.
Closed Thread

Bookmarks

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:56 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