LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 06-13-2005, 03:12 PM   #1
toolshed
Member
 
Registered: Aug 2001
Location: North Ka-Ki-Lak-i
Distribution: Fedora
Posts: 79

Rep: Reputation: 15
Bash script text line into an array


I am trying to read a command and pipe each line into an array.

I want to read:
$chkconfig --list

After I read that command I want to parse each line into 2-d array.
I figure out out to get first line with awk, but not sure how to make it loop till EOF.

$chkconfig --list, when output is just one big text word. It does not preserve the newlines. I wish I token on newlines instead "6:off", because we know runlevel 6 will be off(or should be)


Anyone got in good resources I could look at?

Last edited by toolshed; 06-13-2005 at 03:20 PM.
 
Old 06-13-2005, 06:49 PM   #2
dub.wav
Member
 
Registered: Aug 2003
Location: Norway
Distribution: FC4
Posts: 83

Rep: Reputation: 20
This might work:

Code:
chkconfig --list | while read line
do
  arr=($line)
done
or

Code:
chkconfig --list | while read line
do
 set -- $line # and use $1, $2, $3, etc instead of array indexes.
done
 
  


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
bash shell script read file line by line. Darren[UoW] Programming 51 07-04-2013 09:16 PM
How to replace string pattern with multi-line text in bash script? brumela Linux - Newbie 6 04-21-2011 07:56 AM
Bash Script Array index value Kedelfor Programming 10 04-29-2009 05:37 AM
C++ text file line by line/each line to string/array Dimitris Programming 15 03-11-2008 09:22 AM
MAJOR problem ... bash script array HELP !!!!! michael_util Slackware 1 02-13-2004 07:51 AM


All times are GMT -5. The time now is 11:46 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration