LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-03-2010, 11:09 PM   #1
mech123
Member
 
Registered: Dec 2008
Posts: 36

Rep: Reputation: 16
writing array into file


How can we write arrayValues in file?
Lets say arrayName=(1 2 3 4 5)
Now if i want to write these arrayValues into file
In first line in file :1
In second line in file :2
In third line in file :3
In fourth line in file :4
In fifth line in file :5
 
Old 05-04-2010, 01:32 AM   #2
murugesan
Member
 
Registered: May 2003
Posts: 155

Rep: Reputation: 28
It will be nice to post the program/script name for the query posted here.
 
Old 05-04-2010, 02:30 AM   #3
rajivdp
Member
 
Registered: Oct 2008
Posts: 34

Rep: Reputation: 17
Find the script below for which you need bash shell

Quote:
#!/bin/bash
arrayName=(1 2 3 4 5)
for x in `seq 0 $(( ${#arrayName[@]} - 1 ))`; do
echo "${arrayName[$x]}" >> testing
done
 
1 members found this post helpful.
Old 05-04-2010, 02:39 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,544

Rep: Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898
Or just:
Code:
#!/bin/bash
arrayName=(1 2 3 4 5)

for x in ${arrayName[@]}; do
    echo "$x" >> testing
done
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
need help with writing array elements into a file jayran Linux - Newbie 22 12-16-2009 07:21 AM
bash: use file as input into array, parse out other variables from array using awk beeblequix Linux - General 2 11-20-2009 10:07 AM
3D array in MAT file ->DAT file to read in FORTRAN BrandonPossible Programming 2 07-03-2009 01:14 AM
Writing an ISO file for cd audio from a cue and wave file? spaz-atk Linux - Software 5 12-01-2008 01:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration