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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to store the values in a file into an array risshanth UNIX for Dummies Questions & Answers 3 01-22-2008 06:34 AM
How to read from txt file and use that as an array pinky UNIX for Dummies Questions & Answers 4 10-07-2007 09:18 PM
create array holding characters from sring then echo array. rorey_breaker Shell Programming and Scripting 5 09-28-2007 05:42 AM
Dump an array in a file IMD Shell Programming and Scripting 3 08-31-2006 07:04 AM
File to Array and Back. Boucho High Level Programming 1 02-14-2006 07:32 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-07-2007
Registered User
 

Join Date: Sep 2006
Posts: 20
From File to Array

Hi all,

I want to store the records from a file to an array. What approach can I use?

e.g.
soruce_file:
aaa
bbb
ccc

array:
arr[0]=aaa
arr[1]=bbb
arr[2]=ccc


Thanks,
Rock
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 02-08-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,490
I would take it for guaranted that you had asked for in perl

Code:
#! /opt/third-party/bin/perl
                                                                              
open(FILE, "< filename") || die "Unable to open file. <$!>\n";
                                                                              
while( chomp($content = <FILE>) ) {
  push(@arr1, $content);
}
                                                                              
#If this needs to be displayed
foreach my $var(@arr1) {
  print "$var\n";
}
                                                                              
close(FILE);
                                                                              
exit 0
Reply With Quote
  #3 (permalink)  
Old 02-08-2007
Registered User
 

Join Date: Sep 2006
Posts: 20
thanks a lot
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 10:29 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0