LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to get the key words out of the result (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-get-the-key-words-out-of-the-result-838719/)

Madison00 10-17-2010 09:43 PM

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

grail 10-17-2010 10:07 PM

Based on input this should work for you:
Code:

echo "$db_alive" | awk -F"_" '{print $NF}'
Although you will need to remove your grep entry yourself :)

Madison00 10-18-2010 09:36 AM

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

grail 10-18-2010 10:38 AM

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"

Madison00 10-18-2010 12:50 PM

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.