How to grab last column - Korn Shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to grab last column - Korn Shell
# 1  
Old 10-24-2012
How to grab last column - Korn Shell

I need to grab the last column of data from each line of output from

Code:
ps -ef | grep sshd

Example:

Code:
    root 47645194  1703952   0   Oct 23      -  0:01 sshd: jcagle [priv]
 rnewmon 48694012 27984606   0 08:36:02      -  0:00 sshd: rnewmon@pts/292

Because some of these process have been out there longer than one day there is an extra column so my simple knowledge of awk only works on the ones without the month/day. I understand that I could modify the awk statement to look for column 10 but would rather not have to test if the file line has 10 columns or 9.

Code:
awk '{print $9"}



Thanks for any advice you can provide me.
Justin
# 2  
Old 10-24-2012
Code:
awk '{ print $NF }'

# 3  
Old 10-24-2012
Alternatively, you can use pgrep to feed pids to ps and tell ps to only print the information that interests you.

Regards,
Alister
# 4  
Old 10-24-2012
for sshd data in example listed try:
Code:
ps -ef | grep sshd: | grep -v -E " grep | sed " | sed 's/.*sshd: *//'


Last edited by rdrtx1; 10-24-2012 at 08:12 PM..
# 5  
Old 10-24-2012
Code:
 
ps -ef | awk -F"sshd:" '/sshd:/ && !/awk/ { print $NF } '

# 6  
Old 10-25-2012
Thank you all for your reply. I apologize for the delay in getting that conveyed to you. Once I leave work I try to leave work and just had some other things going this morning and had not started back to work on my script. I have not tried Alister's suggestion yet (I'm sure it works), got to figure out how to get ps to do that but the other suggestions got me what I needed or something to work with. Thanks again.
# 7  
Old 10-25-2012
If pgrep is not available (HP-UX?), you could format the output from ps with the -o option.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

New to korn shell

I am new to korn shell and slowly learning. Is there a way to have a parent script prompt for input and then execute a child script and return the output then move forward and ask for more input and then execute the next child script? I think the answer is no but thought i would ask. (2 Replies)
Discussion started by: cptkirkh
2 Replies

2. Shell Programming and Scripting

grab shell script error

How do I capture an error for any command I use. For e.g if i try to zip a file and the file is not there. The regualr $? -gt 0 only tells its un-successful but won't tell me that the file is not there when I run through a script. How can I capture this error? for e.g.. zip $x.zip $x... (1 Reply)
Discussion started by: dsravan
1 Replies

3. Shell Programming and Scripting

Bourne shell & Korn shell

Could some one tell me the difference btw Bourne shell and the Kshell? Which is more flexible and reliable in terms of portability and efficiency. When i type the following command .. $ echo $SHELL yields me /bin/sh Does this tells me that I am in Bourne shell. If yes, how can i get... (6 Replies)
Discussion started by: bobby1015
6 Replies

4. Shell Programming and Scripting

How to activate Korn Shell functionnalities in Bourne Shell

Hi All I have writing a Korn Shell script to execute it on many of our servers. But some servers don't have Korn Shell installed, they use Borne Shell. Some operations like calculation don't work : cat ${file1} | tail -$((${num1}-${num2})) > ${file2} Is it possible to activate Korn Shell... (3 Replies)
Discussion started by: madmat
3 Replies

5. Shell Programming and Scripting

korn shell

I am using korn shell but I want to have my prompt to represnent that of my C shell because I like it better. Is there anyway to do this? (1 Reply)
Discussion started by: vthokiefan
1 Replies

6. AIX

tsh shell to korn shell

i got stuck in IBM AIX unix and i was googling for the answer. but i didn't find one. can anyone tell me how to get back from tsh# shell to korn shell my system is showing tsh shell in the terminal but i am unable to get back to korn shell. i tried chsh, shell, su, logout, exit commands but not 1... (7 Replies)
Discussion started by: arifkhan
7 Replies

7. UNIX for Dummies Questions & Answers

bourne shell or korn shell?

Hi, I have a script that uses "nohup" command to execute a korn shell script. Which one is the correct shell to use bourne shell or korn shell to execute a korn shell? and why? Thanks in advanced. (2 Replies)
Discussion started by: XZOR
2 Replies

8. Shell Programming and Scripting

how to convert from korn shell to normal shell with this code?

well i have this code here..and it works fine in kornshell.. #!/bin/ksh home=c:/..../ input=$1 sed '1,3d' $input > $1.out line="" cat $1.out | while read a do line="$line $a" done echo $line > $1 rm $1.out however...now i want it just in normal sh mode..how to convert this?... (21 Replies)
Discussion started by: forevercalz
21 Replies

9. Shell Programming and Scripting

KORN Shell - Spawn new shell with commands

I want to be able to run a script on one server, that will spawn another shell which runs some commands on another server.. I have seen some code that may help - but I cant get it working as below: spawn /usr/bin/ksh send "telnet x <port_no>\r" expect "Enter command: " send "LOGIN:x:x;... (2 Replies)
Discussion started by: frustrated1
2 Replies

10. Shell Programming and Scripting

Korn Shell

Hi I am new to shell programming. I need help to write a script to monitor a process on Sun OS. If the process fails then call a oracle procedure. i check the process if running by typing ps -ef | grep ESP | grep -v grep root 29002 1 0 Mar 18 ? 7:20... (4 Replies)
Discussion started by: gpanesar
4 Replies
Login or Register to Ask a Question