LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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-2006, 01:45 AM   #1
nhydra
Member
 
Registered: May 2006
Distribution: Fedora Core, FreeSpire, PC-BSD, NetBSD
Posts: 96

Rep: Reputation: 15
shell script for reading of configuration files


Hello.
I write a shell scripr reading of configuration files. I need to read data from config file. Here is the shell command for extracting the file.

cat renicepid.conf | gawk -F : '/./ {print $2}'

I have this file:
renicepid.conf
//--------------------------------------
Application: -r 2 xterm terminal asdfgh

I need to extract the data after Application:.So, now this work but my question is how to do that if there are many such lines.
Something like this:
//----------------------------------
Application: -r 2 xterm terminal asdfgh
Application: -r 2 aaa dddd ggggg
Application: -r 2 aaa dddd ggggg
Application: -r 2 rrr tt fdgfd dfgsdfgdfg

In that shell command i extract all found lines. I need to have an access to every line.

Thanks in advance.
 
Old 06-13-2006, 02:49 AM   #2
zhangmaike
Member
 
Registered: Oct 2004
Distribution: Slackware
Posts: 376

Rep: Reputation: 31
Code:
cat renicepid.conf | gawk -F : '/./ {print $2}' | while read line; do echo "DO SOMETHING: $line"; done
Just replace echo "DO SOMETHING: $line" with whatever you want to execute for each line.

read reads a single line from stdin and stores it in the specified environment variable.

The while loop will simply execute until read returns an error (when no lines remain to be read).
 
Old 06-13-2006, 03:15 AM   #3
nhydra
Member
 
Registered: May 2006
Distribution: Fedora Core, FreeSpire, PC-BSD, NetBSD
Posts: 96

Original Poster
Rep: Reputation: 15
Thank you. I am very appreciated.
 
  


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
Renaming files in a shell script Mike_the_Man Programming 7 04-17-2006 01:56 PM
put files in the shell script.... Tails1984 Programming 1 02-17-2006 02:33 PM
Configuration files reading Artik Programming 2 06-28-2005 09:35 AM
reading idle time with perl/shell script daryl314 Linux - General 1 12-27-2004 01:11 PM
Shell Script: Reading Pdf files funkymunky Programming 8 06-18-2004 03:34 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:12 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
Open Source Consulting | Domain Registration