LinuxAnswers - the LQ Linux tutorial section.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 06-13-2005, 03:12 PM   #1
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
Registered: Aug 2003
Location: Norway
Distribution: FC4
Posts: 83

Rep: Reputation: 20
This might work:

chkconfig --list | while read line

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


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 55 07-09-2015 01:46 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 06:38 AM.

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