The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-23-2008
ynir ynir is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 35
awk question

For the following code:

Code:
ps auwx | awk -v "PID=${PID}" '$2 == PID {print $LN}'

Two points to clarify:
1. Is the -v flag for declaring we're going to work with a variable?
2. Does the $LN stands for current line? If so, what's wrong with $0? Any difference between them?
Thanks
  #2 (permalink)  
Old 06-23-2008
awk awk is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 134
Quote:
Originally Posted by ynir View Post
For the following code:

Code:
ps auwx | awk -v "PID=${PID}" '$2 == PID {print $LN}'

Two points to clarify:
1. Is the -v flag for declaring we're going to work with a variable?
2. Does the $LN stands for current line? If so, what's wrong with $0? Any difference between them?
Thanks
Hard to tell what you want - so I did this:

Code:
ps auwx | awk -v "PID=${PPID}" '$2 == PID {print }'
xxxxxxx  598114  0.0  0.0  956 1048      - A    08:48:02  0:00 sshd: xxxxxxx@pts/1
prdrept:logs :ps auwx | awk -v "PID=$$" '$2 == PID {print }'
xxxxxxx  479452  0.0  0.0  752  800  pts/1 A    08:48:02  0:00 -ksh

this is using AIX, different systems could handle this differently.
1) LN does not show to be a defined variable in my awk. (I even checked the gawk manual to see if it were there.) Why use $0 when just a simple print will default to the present line.

2) I was not sure if you wanted the current process ($$) or the parent process ($PPID} - ${PID}, was not defined in my version of AIX.
  #3 (permalink)  
Old 06-23-2008
ynir ynir is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 35
Hi "awk", Thanks and sorry for not clarifying enough.

The line is part of a running and working bash script on Linux.
PID is a local variable and the awk line is using its value to print the relevant line from ps.
I don't want to change the code (unless I have too), rather understand why it is used that way.

to simplify it, it is something like:

Code:
function foo()
{
   local MY_PID=""
   #...
   MY_PID=get_my_pid
   LINE=`ps auwx | awk -v "PID=${MY_PID}" '$2 == PID {print $LN}'`
   do_something "${MY_PID}"
}

So, I understand the -v is used to declare variable, since ${MY_PID} will not be resolved inside 'single quotes' - right?

I still don't understand what is the $LN for?
Could anyone clarify? Is it a mistake, that works the same way as print $XXX works ???

Thanks
  #4 (permalink)  
Old 06-24-2008
ynir ynir is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 35
anyone knows something about the $LN ?
  #5 (permalink)  
Old 06-24-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,342
It's not allowed to bump your thread to the top and pushing other peoples threads to the bottom.
Please read our rules.
  #6 (permalink)  
Old 06-24-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,342
The $ sign is used to print fields and AFAIK LN is not an awk variable.....

Regards
Closed Thread

Bookmarks

Tags
linux, solaris

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:10 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0