![]() |
|
|
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 |
| ps avg | grep ? filter the desired out put. | varungupta | UNIX for Advanced & Expert Users | 1 | 04-10-2009 05:30 PM |
| Grep script to filter | kevin9 | Shell Programming and Scripting | 2 | 02-21-2009 01:59 AM |
| how to filter `last` command for yesterday only | skully | Shell Programming and Scripting | 1 | 06-26-2008 05:30 AM |
| grep a log file to filter previous dates | pinpe | Shell Programming and Scripting | 5 | 08-03-2007 02:25 PM |
| Filter results through pipe with grep | ckandreou | UNIX for Dummies Questions & Answers | 1 | 07-10-2006 03:04 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
filter grep command
I have ran into a small issue and I am not sure how to fix it. In one of our current scripts we have this line which does a grep to get the pid of the process. Code:
ps -ef | grep nco_p_syslog | grep $x | awk '{print $2}'
However this is not returning anything due to the how long the value of $x is. Which a sample value is... Code:
ot1p_stdby However as you can see a simple grep cuts this off... Code:
tivoli 20343 1 0 10:16:09 pts/1 0:00 /lcl/apps/Tivoli/netcool/omnibus/probes/solaris2/nco_p_syslog -manager ot1p_std I need to find a way to do a grep command like below only have it know off the _stdby contained within $x. So that even though $x contains the value ot1p_stdby it should cutt off the _stdby and only by ot1p when it does the following command.,,, Code:
ps -ef | grep nco_p_syslog | grep $x | awk '{print $2}'
I was not sure if there is a way to do this right in the command above. Thanks |
|
||||
|
Gave it a try but got this... Code:
leviathan:/lcl/apps/Tivoli/netcool/omnibus/bin>./test.sh
./test.sh[3]: "${x:0:8}": bad substitution
leviathan:/lcl/apps/Tivoli/netcool/omnibus/bin>
Here is how I am testing... Code:
#!/bin/ksh
x=entp_stdby
ps -ef | grep nco_p_syslog | grep "${x:0:8}" | awk '{print $2}'
Changed the " to ' and that fixed the error... Code:
leviathan:/lcl/apps/Tivoli/netcool/omnibus/bin>./test.sh
./test.sh[3]: '${x:0:8}': bad substitution
leviathan:/lcl/apps/Tivoli/netcool/omnibus/bin>
But still no results. Seems like that would have worked. I see where you was going with it. It should have take the $x which has a value of entp_stdby and only did a grep for entp_std but it returned no results. As you can see it should have returned results as this is running out there. Code:
leviathan:/lcl/apps/Tivoli/netcool/omnibus/bin>ps -ef | grep syslog | grep entp_std tivoli 20337 1 0 10:16:09 pts/1 0:01 /lcl/apps/Tivoli/netcool/omnibus/probes/solaris2/nco_p_syslog -manager entp_std |
|
||||
|
That's interesting, as on my workstation (Debian Linux 5 feat. Bash), this works ... Code:
[house@leonov] a='nco_p_syslog -manager ot1p_std'; x='ot1p_stdby'; echo $a | grep "${x:0:8}"
nco_p_syslog -manager ot1p_std
Anyway, how about skipping single as well as double quotes entirely, as follows ... Code:
[house@leonov] a='nco_p_syslog -manager ot1p_std'; x='ot1p_stdby'; echo $a | grep ${x:0:8}
nco_p_syslog -manager ot1p_std
|
|
||||
|
Yep now that works. It also shows the pid for the grep itself though as well. I am trying to figure out how this is working, lol. Lost me on this one. How can I make it so it does not return 2 pids and only the one I am looking for. Right now its returning the pid for this grep as well. Code:
leviathan:/lcl/apps/Tivoli/netcool/omnibus/bin>./test.sh 10572 20337 Quote:
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|