Use of cut to extract process name


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Use of cut to extract process name
# 1  
Old 06-19-2012
Use of cut to extract process name

Hi all,

I am trying to formulate a command to extract a section of the output of ps -ef,

for example I need to extract the 'plt11dm1' of the following output
Code:
oracle   20132     1  0 May12 ?        00:03:30 ora_smon_plt11dm1

I thourght of using
Code:
ps -ef -o comm|grep ora_smon|grep -v grep|cut -c10-30

But it doesnt seem to work when using /etc/bash shell

Any ideas?

thanks in advance,

John

Last edited by Franklin52; 06-19-2012 at 06:29 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 06-19-2012
Code:
| awk -F'_' '{print $NF}'

# 3  
Old 06-19-2012
Hi,

Try the following;

Code:
ps -ef -o comm|grep ora_smon|grep -v grep|awk '{ print $8 }'

Regards

Dave
# 4  
Old 06-19-2012
Hi all,

Thanks but I get a consistent error when I run -o comm

Code:
ps -ef -o comm|grep ora_smon|grep -v grep|awk '{ print $8 }'

Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.7/FAQ

I get this error when I run my command.

---------- Post updated at 10:39 AM ---------- Previous update was at 10:37 AM ----------

If I run;

Code:
ps -ef |grep ora_smon|grep -v grep|awk '{ print $8 }'

then I get

Code:
ora_smon_plt11dm1
ora_smon_plt11cr1
ora_smon_plt10cr1
ora_smon_plt10dm1


Which is nearly there.

But I just need the name, ie plt11dm1 etc..

Last edited by Scrutinizer; 06-19-2012 at 06:41 AM.. Reason: code tags
# 5  
Old 06-19-2012
Try this ..
Code:
$ ps -ef | grep ora_smon| grep -v grep | awk '{split($8,a,"_"); print a[3]}'

# 6  
Old 06-19-2012
thnx for your helpSmilie
# 7  
Old 06-19-2012
Save a process by changing this:
Code:
grep ora_smon| grep -v grep

to this:
Code:
grep [o]ra_smon

Matches the string "ora_smon" but not itself ("[o]ra_smon").

Last edited by gary_w; 06-19-2012 at 03:46 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. HP-UX

How to extract data for a specific process from ovpa?

Hi Friends, One question. Supposed I want to extract data only for process named "sqlplus" how can I do it. Any suggestions? I don't want all the data as it is not useful to me e.g.. Command I use is given below extract -xp -p -r repfile -b"03/15/13 7:00 PM" -e"03/15/13 09:30 PM" -f... (1 Reply)
Discussion started by: kunwar
1 Replies

2. UNIX for Dummies Questions & Answers

[Solved] Extract a pattern using sed or cut

Hi, Need help to extract a pattern using sed or cut or any other means. Input 'name1',1234567890 'name2',2222222222 'name3',3333333333 Expected output name1,1234567890 name2,2222222222 name3,3333333333 (3 Replies)
Discussion started by: mukulverma2408
3 Replies

3. Shell Programming and Scripting

sed or awk, cut, to extract specific data from line

Hi guys, I have been trying to do this, but... no luck so maybe you can help me. I have a line like this: Total Handled, Received, on queue Input Mgs: 140 / 14 => 0 I need to, get the number after the / until the =, to get only 14 . Any help is greatly appreciated. Thanks, (4 Replies)
Discussion started by: ocramas
4 Replies

4. Shell Programming and Scripting

extract/cut desired output from a line

Hi all , my script is sending output to a file , output is in below format :- i want to cut , celltadm@avm-siapp01 from this output line . Starting and ending words can vary , like it can be any name as below - so there will be only one "@" and i want to cut word just before and after... (8 Replies)
Discussion started by: deepakiniimt
8 Replies

5. Shell Programming and Scripting

need to extract terminal from this process -perl regx

Hi All, i ve a process, user4 31779 2836 0 01:43 pts/6 00:00:00 sh /home/user/DATE/SUT_SCR/c.sh like this i'll get so many process when in run ps -ef | grep pts | grep c.sh i need to extract terminal id from this string. i.e pts/6, or sometimes pts/22 same way i need to do for... (3 Replies)
Discussion started by: asak
3 Replies

6. Shell Programming and Scripting

Cut Command error cut: Bad range

Hi Can anyone what I am doing wrong while using cut command. for f in *.log do logfilename=$f Log "Log file Name: $logfilename" logfile1=`basename $logfilename .log` flength=${#logfile1} Log "file length $flength" from_length=$(($flength - 15)) Log "from... (2 Replies)
Discussion started by: dgmm
2 Replies

7. UNIX for Dummies Questions & Answers

using cut to extract info

a simple question, how can i use cut (after using grep) to extract the last four digits on a line. so say i had a string http://blabla:9020, how would I extract the port?? -Fez (4 Replies)
Discussion started by: hafhaq
4 Replies
Login or Register to Ask a Question