how to get the key words out of the result
Below is the result:
oracle 5891 1 0 Aug02 ? 00:03:20 ora_pmon_test1 oracle 6274 1 0 Sep24 ? 00:00:27 ora_pmon_newB1 oracle 7246 1 0 Aug02 ? 00:00:54 ora_pmon_emrep1 oracle 8880 1 0 Aug04 ? 00:03:27 ora_pmon_oem1 oracle 14125 1 0 Jun25 ? 00:00:22 asm_pmon_+ASM1 oracle 18414 1 0 Aug04 ? 00:02:41 ora_pmon_clone10g1 test 18554 574 0 19:33 pts/0 00:00:00 grep pmon if I do: $ cat $db_alive | cut -f3 -d: I got: 20 ora_pmon_test1 27 ora_pmon_newB1 54 ora_pmon_emrep1 27 ora_pmon_oem1 22 asm_pmon_+ASM1 41 ora_pmon_clone10g1 00 grep pmon All I want is the name of the sid name which is the last word on every line like" test1 newB1 emrep1 oem1 +ASM1 clone10g1 |
Based on input this should work for you:
Code:
echo "$db_alive" | awk -F"_" '{print $NF}' |
below is what I had in the code, maybe I missed something b/c it doesn't seem to work.
#!/bin/ksh HOME="/home/" DATE=$(date) HOSTNAME=$(hostname) ps -ef |grep pmon > pmon.txt db_alive=$HOME/pmon.txt echo "$db_alive" | awk -F"_" '{print $NF}' executed the above script and the result: $ ./test2* /home/pmon.txt thx |
That would be because it is a file reference where from your example I thought it was a string. Change it to:
Code:
awk -F"_" '{print $NF}' "$db_alive" |
Thanks Grail.
I am new and still learning with scripting. Another question, what is each of the command do: awk -F"_" '{print $NF}' thanks so mcuh. |
All times are GMT -5. The time now is 11:36 PM. |