Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am working on shell script where i want to store O/P of the command in array. I have a file containing rows & columns from where i want to extract 3rd column & store all values in a array. if suppose i have below in my file info.txt

  abc  xyz  pqr  akl
  mnt  var  man  lak
  qer  tag  sam  bob

I want to store pqr, man and sam in array lets call name[1], name[2], name [3]

Can someone please help me with this.

share|improve this question

closed as off-topic by Tim Brigham, Aaron Copley, mdpc, Ward, growse Jul 2 '13 at 10:09

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about software development are off-topic here, but can be asked on Stack Overflow." – Tim Brigham, Aaron Copley, mdpc, growse
If this question can be reworded to fit the rules in the help center, please edit the question.

name=( $(cut -d ' ' -f 3 "./info.txt") )

will do what you want (starting with index 0 however).

share|improve this answer

You can also do:

  name=( $(awk '{print $3}' ./info.txt) )

I find this a little simpler. You can then access the array like ${name[1]} ${name[2]} or use * instead of a number for all elements.

share|improve this answer
Hey Thanks for the solution. – Shailesh Sutar Jul 2 '13 at 12:47
If you used it, perhaps you would like to accept it as the answer? – user160910 Jul 11 '13 at 13:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.