Unix Technical Forum

Re: Using an awk program

This is a discussion on Re: Using an awk program within the Sco Unix forums, part of the Unix Operating Systems category; --> Ronald J Marchand wrote: > "Stuart J. Browne" <stuart@promed.com.au> wrote in message > news:413f9da9@dnews.tpgi.com.au... > > > Using an ...


Go Back   Unix Technical Forum > Unix Operating Systems > Sco Unix

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-15-2008, 04:07 PM
Tony Lawrence
 
Posts: n/a
Default Re: Using an awk program


Ronald J Marchand wrote:
> "Stuart J. Browne" <stuart@promed.com.au> wrote in message
> news:413f9da9@dnews.tpgi.com.au...
> > > Using an awk program, I am trying to set the values of pid and

pseudo in
> > > a
> > > shell script to be used in other commands. So far I have:
> > > :
> > > logname=digna
> > > pid=
> > > pseudo=
> > > ps -ef | grep xcrt | awk -v user=$logname -v pid=$pid -v

pseudo=$pseudo
> '
> > > ( $1 == user && $8 == "/usr/lib/merge/xcrt" ) { print

$1,$2 }
> > > ( $1 == user && $8 == "/usr/lib/merge/xcrt" ) { pid = $2 }
> > > ( $1 == user && $8 == "/usr/lib/merge/xcrt" ) { pseudo =

$6 }
> > > '
> > > echo $pid
> > > echo $pseudo
> > > exit
> > >
> > > This program executes fine. It just doesn't set pid & pseudo.
> > > Could some kind soul show mercy and explain the error?????

> >
> > So you want the environment variables 'pid' and 'pseudo' after ther

fact?
> > you can't do that.
> >
> > You either use ``'s to fill them, or you do everything from within

awk.
> >
> > Example:
> >
> > #!/usr/bin/awk -f
> > BEGIN {
> > cmd = "/bin/ps -fU " ENVIRON["logname"]
> > while ( cmd | getline ) {
> > if ( $8 ~ /xcrt$/ ) {
> > pid = $2
> > pseudo = $6
> > system( "<do command here>" )

>
> This I will explore. thanks
>
> > }
> > }
> > close( cmd )
> > }
> >
> > If you just want to populate environment variables in a shell for
> > lots-of-other-purposes, then you'd have to use it completely

differently:
> >
> > :
> > pid=`ps -fU $logname | awk '$8 ~ /xcrt$/ { print $2 }'`
> > pseudo=`ps -fU $logname | awk '$8 ~ /xcrt$/ { print $6 }'`
> >
> > However, if there are multiple PID's for this one, it will only

grab the
> > 'last' PID/TTY pair.

>
> I am aware of how to use accent grave to set a variable in the

caller. While
> this little project has a purpose, it is also a learning project on

the use
> of awk. I just hoped that if you could pass one piece of information

back
> to the caller, there could be a way to pass multiple variables.

Apparently
> not. It seems inefficient to run the same (similar) script several

times.

Well, there are many ways to pass information back: data files, shared
memory, named pipes, and even reading information the called program
prints to the screen. There are so many ways to do it that exactly HOW
really depends on what your needs are more than anything else.

And btw, you would be SO much better off using Perl..
--
Tony Lawrence

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-15-2008, 04:07 PM
Ronald J Marchand
 
Posts: n/a
Default Re: Using an awk program

"Tony Lawrence" <pcunix@gmail.com> wrote in message
news:chq4qn$j56@odah37.prod.google.com...
>

<< snipped>>
>
> And btw, you would be SO much better off using Perl..
> --
> Tony Lawrence
>

I hear you :-)


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 11:12 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com