Need to cut the string in the result generated by AWK
HI ,
I wanted to get the ORACLE_HOME of the listener's running on the server I have been using the following to get the reult /opt/oracle/admin/PHYPE/bdump> ps -ef|grep /bin/tnslsnr|grep -v grep|awk '{print $9}' Result is as follows /opt/oracle/product/10.2/bin/tnslsnr /opt/oracle/product/9.2.0/bin/tnslsnr /opt/oracle/product/10.2/bin/tnslsnr /opt/oracle/product/10.2/bin/tnslsnr /opt/oracle/product/9.2.0/bin/tnslsnr /opt/oracle/product/10.2/bin/tnslsnr Now i wanted to cut the /bin/tnslsnr part and the remaining should write to the file Anyone please help me !!! Thanks, Naveen. |
If there are always 4 components to PATH like that:
then piping what you have into awk -F/ '{print "/"$2"/"$3"/"$4"/"$5}' would work. The "-F/" changes the field separator from space to "/". In the print side you have to put the slashes back in. Alternatively you could play with setting the OFS variable for the output field separator if the input had variable length paths. |
Many shells (bash, zsh) support cutting ... do something like this:
Code:
for i in `ps ax --format cmd | grep "[/]bin/tnslsnr" | sort | uniq`; do |
Geez ... how about we do away the slew of unnecessary greps and just let awk do its thing:
Code:
ps -ef | awk '"/bin/tnslsnr" && !/awk/{print gensub("/bin/tnslsnr","","g",$9)}' |
Code:
ps -eo args |grep "/bin/tnslsn[r]" |sed 's|\/bin\/tnslsnr$||' |
All times are GMT -5. The time now is 09:18 AM. |