The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
How to store the values in a file into an array risshanth UNIX for Dummies Questions & Answers 3 01-22-2008 10:34 AM
How to read from txt file and use that as an array pinky UNIX for Dummies Questions & Answers 4 10-08-2007 12:18 AM
create array holding characters from sring then echo array. rorey_breaker Shell Programming and Scripting 5 09-28-2007 08:42 AM
Dump an array in a file IMD Shell Programming and Scripting 3 08-31-2006 10:04 AM
File to Array and Back. Boucho High Level Programming 1 02-14-2006 11:32 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-08-2007
Rock Rock is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 23
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
  #2 (permalink)  
Old 02-08-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,932
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
  #3 (permalink)  
Old 02-08-2007
Rock Rock is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 23
thanks a lot
Sponsored Links
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 03:03 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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