![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| ls -laR | grep "^-" | awk '{print $9}'| grep "$.txt" | DNAx86 | Shell Programming and Scripting | 13 | 04-17-2008 11:53 PM |
| Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" | Lokesha | UNIX for Dummies Questions & Answers | 4 | 12-20-2007 01:52 AM |
| grep to find content in between curly braces, "{" and "}," | keshav_rk | Shell Programming and Scripting | 4 | 08-09-2007 10:14 PM |
| grep/cat/more -- search in a txt file and display content from a specific "keyword" | I-1 | UNIX for Dummies Questions & Answers | 4 | 02-21-2007 04:57 AM |
| Print The ouput From ls | grep "!!!" | geoquest | UNIX for Advanced & Expert Users | 5 | 04-11-2002 05:45 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else
Hi Guys,
I need to set the value of $7 to zero in case $7 is NULL. I've tried the below command but doesn't work. Any ideas. thanks guys. MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else { print $7}}' ` Harby. |
|
||||
|
Anything will match the empty string; regular expressions look for a match anywhere, and finding "nothing" anywhere trivially matches. You need to anchor it to make it more picky about what to find. $7 ~ /^$/ checks for an empty string (beginning of string adjacent to end of string) but it's probably more efficient to simply use equivalence comparison against the empty string.
Also, avoid the Useless Use of grep | grep | awk. Code:
MEM=`ps v $PPID | awk 'tolower ($0) ~ /[d]b2/ { if ($7 == "") print 0; else print $7; }
Last edited by era; 09-18-2008 at 02:06 AM.. Reason: Regex vs equivalence |
|
||||
|
hi ,
Thanks for your reply. For some reason still doesn't work for me. I took some parts of your command to at least get it to work using : MEM=`ps v $PPID | grep -i db2| awk '{ if ($7 == "") print 0; else print $7; }` and with the debug on I get the below: MEM2=175804 + + ps v 1790056 + grep -i db2 + awk { if ($7 == "") print 0; else print $7; } MEM= so you can see that the variable MEM suppose to be set to 0 but is not. Thanks again and thanks for your sugesstions. It take a while to come with a good coding techniques. ![]() |
|
||||
|
Hi ,
Yes the grep is returning the PPID's and then I execute a ps v PPID as you can see below: MEM=15244 + + bc + echo 1567008 + 15244 MEM2=1582252 + + ps v 1847476 + grep -i db2 + awk { if ($6 == "") print 0; else print $6; } MEM=16824 + + bc + echo 1582252 + 16824 MEM2=1599076 + + ps v 1896670 + grep -i db2 + awk { if ($6 == "") print 0; else print $6; } MEM=11072 + + bc + echo 1599076 + 11072 MEM2=1610148 + + ps v 1900608 + grep -i db2 + awk { if ($6 == "") print 0; else print $6; } MEM=13840 + + bc + echo 1610148 + 13840 MEM2=1623988 + + ps v 1912972 + grep -i db2 + awk { if ($6 == "") print 0; else print $6; } MEM=15404 + + bc + echo 1623988 + 15404 MEM2=1639392 + + ps v 1925356 + grep -i db2 + awk { if ($6 == "") print 0; else print $6; } MEM=16752 + + bc + echo 1639392 + 16752 MEM2=1656144 + + ps v 1974472 + grep -i db2 + awk { if ($6 == "") print 0; else print $6; } MEM=16012 + + bc + echo 1656144 + 16012 MEM2=1672156 + + ps v 1998882 + grep -i db2 + awk { if ($6 == "") print 0; else print $6; } MEM=15852 + + bc + echo 1672156 + 15852 MEM2=1688008 + + bc + echo 1688008 / 1024 TOTAL=1648 |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|