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.