Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old August 18th, 2008, 09:20 AM
Newbie
 
Join Date: Aug 2008
Location: Bangalore
Posts: 5
Default Can't Understand the awk prog.in this script.and why '/' before $ symbol

strFree="stmnt"
strImportantType="coldimpnt"



intUID=$(ps -fu lower | awk "/${strFree}/ && /${strImportantType}/ && ! /awk/ "'{ print $2 }')

where lower is the user.
Reply
  #2  
Old August 18th, 2008, 10:28 AM
ashitpro's Avatar
Expert
 
Join Date: Aug 2007
Posts: 297
Default

'strFree' and 'strImportantType' are variables with values 'stmnt' and 'coldimpnt' resp.
Then...
When you say...${strFree}, it means value of that variable..
So..."/${strFree}/some_other_directory" will get expand to.
"/stmnt/some_other_directory"
Reply
  #3  
Old August 18th, 2008, 01:57 PM
Newbie
 
Join Date: Aug 2008
Location: Bangalore
Posts: 5
Default

then why && is there in between the directory path.Is it checking the true/falsity of the stmt. /${strFREE}.

if yes then what for is it checking,as bcoz we have already set the value of the variable.

And what does " ! /awk/ " denonetes in the prog.
Reply
  #4  
Old August 19th, 2008, 08:01 AM
ashitpro's Avatar
Expert
 
Join Date: Aug 2007
Posts: 297
Default

Quote:
Originally Posted by sanishr
then why && is there in between the directory path.Is it checking the true/falsity of the stmt. /${strFREE}.

if yes then what for is it checking,as bcoz we have already set the value of the variable.

And what does " ! /awk/ " denonetes in the prog.

I apologize for previous reply...
This script is used to print the PID of the processes which are own by the specific user...

ps -fu lower

this command will give you the list of processes owned by user 'lower'

Now lets see the awk..

cat file_name | awk "/abc/ && /pqr/"

this command is used to search for 'abc' as well as 'pqr' in same line..
So if any line in file 'file_name' contains 'abc' and 'pqr', will get displayed.

Coming back to your script...

ps -fu lower | awk "/abc/ && /pqr/ ! /awk/"

It will search for line which contains 'abc' and 'pqr' and does not contain 'awk'

ps -fu lower | awk "/abc/ && /pqr/ ! /awk/"'{print $2}'

and for last statement 'print $2' it will print the second field i.e. PID(in my case).
Reply
  #5  
Old August 19th, 2008, 10:53 AM
Newbie
 
Join Date: Aug 2008
Location: Bangalore
Posts: 5
Default

what is the need of giving '/' in (ps -fu lower | awk "/abc/ && /pqr/ ! /awk/")
can't we write like this for the same functionality (ps -fu lower | awk "abc && pqr ! awk")
Reply
  #6  
Old August 19th, 2008, 12:34 PM
ashitpro's Avatar
Expert
 
Join Date: Aug 2007
Posts: 297
Default

Quote:
Originally Posted by sanishr
what is the need of giving '/' in (ps -fu lower | awk "/abc/ && /pqr/ ! /awk/")
can't we write like this for the same functionality (ps -fu lower | awk "abc && pqr ! awk")
/regex/ This syntax is used for specifying regular expressions...
In above example everything will work fine even if you omit the slashes..
Reply
Reply

Bookmarks

Thread Tools

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 Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles