|
Problem 1:
I am getting input like below: Code: $ ps -ef | grep pmon | grep -v asm | grep -v grep
I want the output like below. Currently I can achieve via two awk commands but is there any way can do by one command. Code: $ ps -ef | grep pmon | grep -v grep | grep -v asm | awk
'{print $1}'
Code: expected output :
Solution 1: Try: Code: ps -ef | grep pmon | grep -v grep | grep -v asm | awk
'
Or if want to avoid the some of the pipes, Code: ps -ef | awk '/pmon/ && !/asm/ && !/grep/
{x=$1;gsub(/.*_/,_);print x FS $0}'
Code: ps -ef | awk '/pmon/ && !/asm/ && !/grep/
{gsub(/.*_/,_);print "oracle " $0}'
Another version could be : Code: ps -ef | awk '/pmon/ && !/asm|grep/ {gsub(/.*_/,_);print "oracle " $0}' --- Problem 2: I have a scenario where in, I have a file named abc.txt.
Code: awk '/dbf$/{print $NF}' abc.txt
Now I need to further enhance this command and also extract
the mount point details using df -k
Code: The mount point details for '/u01/oradata/omc/systab/omcdef.dbf' are: /u01/oradata/omc/systab (/dev/vx/dsk/omcdg/systab_v) :
15080098 total allocated Kb
The mount point details for '/u01/oradata/omc/oratemp/temptab1.dbf' are: /u01/oradata/omc/oratemp (/dev/vx/dsk/omcdg/oratemp_v)
: 11305721 total allocated Kb
How do I achieve this with AWK? Solution 2: Try to use Following : Code: for i in `awk '/dbf$/{print $NF}' abc.txt`
Or using an array to minimize the calls to awk : Code: #!/bin/bash
|
|
See Also
Have a Unix Problem
Unix Books :-
Return to : - Unix System Administration Hints and Tips (c) www.gotothings.com All material on this site is Copyright.
|