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
matching each line in a column to an array greptastic UNIX for Dummies Questions & Answers 2 11-11-2008 03:42 PM
bash array problem yagnesh Shell Programming and Scripting 1 08-19-2008 03:48 AM
[BASH - KSH] Passing array to a function ripat Shell Programming and Scripting 3 04-17-2008 09:17 AM
bash:awk output into an array phamp008 Shell Programming and Scripting 2 03-16-2008 05:14 AM
bash array gubten Shell Programming and Scripting 1 12-08-2006 04:47 PM

Reply
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 10-16-2009
Dedalus Dedalus is offline
Registered User
  
 

Join Date: May 2009
Location: Italy/France
Posts: 60
bash Column to array

Hi

I have a file with just one column, and i'd like to save it in a bash array.

file_in
Quote:
word1
word2
word3
word4
then, i want save the column in a bash array in order to get:

Code:
array[0]==word1, array[1]==word2....array[3]==word4
I can't figure out how to do it. Can anyone help please?

thanks
D

EDIT: Sorry, i solved. I've found the solution here in another post. thx. here the post: saving values from awk expression into shell array

Last edited by Dedalus; 10-16-2009 at 09:43 AM..
  #2 (permalink)  
Old 10-16-2009
dr.house dr.house is offline
Registered User
  
 

Join Date: Dec 2008
Location: Switzerland
Posts: 227
What may or may not work:

Code:
ARRAY=( $( cat in.file ) )
  #3 (permalink)  
Old 10-16-2009
Dedalus Dedalus is offline
Registered User
  
 

Join Date: May 2009
Location: Italy/France
Posts: 60
Yea as i edited in the first post i found there the same solution you suggest.

thanks for help

D
  #4 (permalink)  
Old 10-18-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361
Code:
array=( $( < "$file" ) )
Or, with bash 4.0:

Code:
mapfile -t array < "$file"

Last edited by cfajohnson; 10-18-2009 at 01:05 AM..
  #5 (permalink)  
Old 10-19-2009
Dedalus Dedalus is offline
Registered User
  
 

Join Date: May 2009
Location: Italy/France
Posts: 60
thanks for the different solution

D.
Reply

Bookmarks

Tags
array, bash, column

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