By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,332 Members | 1,148 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,332 IT Pros & Developers. It's quick & easy.

Can't Understand the awk prog.in this script.and why '/' before $ symbol

P: 5
strFree="stmnt"
strImportantType="coldimpnt"



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

where lower is the user.
Aug 18 '08 #1
Share this Question
Share on Google+
5 Replies

ashitpro
Expert 100+
P: 542
'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"
Aug 18 '08 #2

P: 5
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.
Aug 18 '08 #3

ashitpro
Expert 100+
P: 542
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).
Aug 19 '08 #4

P: 5
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")
Aug 19 '08 #5

ashitpro
Expert 100+
P: 542
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..
Aug 19 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.