Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting lines from a file for given condition. 1

Status
Not open for further replies.

Bootstrap

Technical User
Nov 9, 2001
12
US
Hi All,

I am trying to extract certain lines from file.cfg. file.cfg has uniform entries such as:

Name of Service A
Condition=Start
Min=1, MAX=10

Name of Service B
Condition=Manual
Min=3, Max=5

Name of Service C
Condition=Start
Min=0, Max=2

There are numerous entries like this. I am trying to create a script that will display the three lines of only the entries that have "Condition=Start". My trouble is to pull the lines that appear before and after the line "Condition=Start".

The goal is to quickly see what service entries in file.cfg are set to start without viewing file.cfg.

Thanks in advance.

Robert

 
FYI. I have now registered and no longer am a dreaded VISITOR!!!

Robert
 
Use this awk program
Code:
/^Name/ {hld = $0}
/^Condition=Start/{print hld; print; getline; print}
Hope this helps.
CaKiwi
 
Robert :) Visitors are a good thing, we're all Visitors before we register...

Anyway - Welcome. Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Thanks CaKiwi.

I was able to use your suggestion to create a script that does excatly what I need. Thanks again.

Robert
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top