Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Re: question on...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 2122 of 2317
Post > Topic >>

Re: question on awk

by Ed Morton <morton@[EMAIL PROTECTED] > Jan 4, 2008 at 11:12 AM

On 1/4/2008 10:39 AM, Zinger wrote:
> Hi All,
> 
> I want to be able to read the contents of a file as below:-
> 
> ==================================
> There are 4 occurrences
> 
> These occurrences are listed below:
> machine1---RUNNING
> machine2---STOPPED
> machine3---WORKING
> machine4---RUNNING
> 
> ==================================
> 
> I want the script to pick all the machines in RUNNING state i.e.
> machines1 and 4 and assign their names to a variable for further
> manipulation.
> 
> Do I use awk?

Please don't multi-post as this was already answered in comp.lang.awk
under the
assumption this was strictly an awk question:

Yes:

   awk -F- '$NF=="RUNNING"{print $1}' file

To assign each name to a variable as you go would be:

   awk -F- '$NF=="RUNNING"{var = $1}' file

but that obviously wouldn't produce any output and may not be the best
approach.
You'd have to tell us what the "further manipulation" is for more help
with that.

When you say "assign their names to a variable" do you mean an awk
variable or a
shell variable? If you're looking to just write an awk script, post
followups to
comp.lang.awk. If you're looking to embed awk in a longer shell script or
aren't
sure how to proceed, post followups to comp.unix.shell.

	Ed.
 




 1 Posts in Topic:
Re: question on awk
Ed Morton <morton@[EMA  2008-01-04 11:12:03 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 15:08:09 CDT 2008.