LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-17-2010, 10:43 PM   #1
Madison00
LQ Newbie
 
Registered: Oct 2010
Posts: 10

Rep: Reputation: 0
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
 
Old 10-17-2010, 11:07 PM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,243

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
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
 
Old 10-18-2010, 10:36 AM   #3
Madison00
LQ Newbie
 
Registered: Oct 2010
Posts: 10

Original Poster
Rep: Reputation: 0
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

Last edited by Madison00; 10-18-2010 at 10:49 AM.
 
Old 10-18-2010, 11:38 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,243

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
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"
 
Old 10-18-2010, 01:50 PM   #5
Madison00
LQ Newbie
 
Registered: Oct 2010
Posts: 10

Original Poster
Rep: Reputation: 0
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete text between key words : sed shalomajay Programming 7 05-11-2011 07:22 PM
Email server that blanks out key words... c1scok1d Linux - Server 1 09-17-2009 06:49 PM
IMAP key words a7mlinux Linux - General 3 08-18-2009 11:14 AM
find a key words in a file ashley75 Linux - General 3 08-29-2007 05:30 PM
Key in Chinese/Japanese words WindowsKiller SUSE / openSUSE 1 11-08-2005 08:50 PM


All times are GMT -5. The time now is 08:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration