Latest LQ Deal: Latest LQ Deals
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-2006, 02:45 AM   #1
Registered: May 2006
Distribution: Fedora Core, FreeSpire, PC-BSD, NetBSD
Posts: 96

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

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:
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, 03:49 AM   #2
Registered: Oct 2004
Distribution: Slackware
Posts: 376

Rep: Reputation: 31
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, 04:15 AM   #3
Registered: May 2006
Distribution: Fedora Core, FreeSpire, PC-BSD, NetBSD
Posts: 96

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


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

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