by loki harfagr <loki@[EMAIL PROTECTED]
>
Jan 4, 2008 at 04:51 PM
On Fri, 04 Jan 2008 08:24:46 -0800, 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?
Well, the real answer depends much on the rest of what you
expect to do overall, but just supposing you really want to
fill a variable with previous problem description, it's
possible to do for instance:
$ woooop=$(awk '$NF=="RUNNING"{print $1}' FS=- yourfile)
or backticks instead of ba****sm:
$ woooop=`awk '$NF=="RUNNING"{print $1}' FS=- yourfile`
then use your variable at your will:
$ echo ${woooop}
machine1 machine4
$ echo "${woooop}"
machine1
machine4