Ps output field extract


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Ps output field extract
# 1  
Old 04-10-2013
Ps output field extract

This is the output from ps -ef cmd . I have to extract the fourth (C) and the seventh (TIME) field
Code:
root 3932344 3801216      Apr 08      -  0:00 /usr/sbin/rsct/bin/ERrmd
 root 3997836       1       0   Apr 08      -  0:00 /usr/sbin/uprintfd
 root 4128894 3801216   0   Apr 08      -     0:09 /usr/sbin/rsct/bin/rmcd -x
root 4325512       1        1   Apr 08      -     3:21 /usr/sbin/getty /dev/console
root 4391046 3801216     0   Apr 08      -      0:00 /bin/ksh/
 root 5439640 6815806   1    12:32:31  pts/0  0:00 -ksh

I have used cut -d " " -f4 to extract the 4th but need some help to extract the 7th field . cut -d " " -f7 can't be used because of the STIME(Apr 08).

Thanks for help

Last edited by joeyg; 04-10-2013 at 09:05 AM.. Reason: Please wrap data and script commands within CodeTags
# 2  
Old 04-10-2013
Why not...

extract the 7th and 8th fields if date is in two fields?
# 3  
Old 04-10-2013
ps output

Code:
root 4391046 3801216     0   Apr 08      -      0:00 /bin/ksh/
root 5439640 6815806   1    12:32:31  pts/0  0:00 -ksh

Date can have both this format

Last edited by zaxxon; 04-10-2013 at 10:06 AM.. Reason: code tags
# 4  
Old 04-10-2013
If you don't require all of the fields in -ef output, then don't use -ef. Your ps can probably be told to only output the two fields sought. Refer to your man page.

Regards,
Alister
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Combine Similar Output from the 2nd field w.r.t 1st Field

Hi, For example: I have: HostA,XYZ HostB,XYZ HostC,ABC I would like the output to be: HostA,HostB: XYZ HostC:ABC How can I achieve this? So far what I though of is: (1 Reply)
Discussion started by: alvinoo
1 Replies

2. Shell Programming and Scripting

Extract lines whose third field is 0

Hi, I have a file with colon separated values like below. How can i get those lines whose third field is 0 (zero). In the below example, lines starting with stapler and tempo has its third field as 0 $ cat list.txt galaxy:b:5:world stapler:a:0:hello abc:a:4:stomper kepler:uic:5:jam... (8 Replies)
Discussion started by: John K
8 Replies

3. Shell Programming and Scripting

Plz Help. Compare 2 files field by field and get the output in another file.

Hi Freinds, I have 2 files . one is source.txt and second one is target.txt. I want to keep source.txt as baseline and compare target.txt. please find the data in 2 files and Expected output. Source.txt 1|HYD|NAG|TRA|34.5|1234 2|CHE|ESW|DES|36.5|134 3|BAN|MEH|TRA|33.5|234... (5 Replies)
Discussion started by: i150371485
5 Replies

4. Shell Programming and Scripting

Compare two files Field by field and output the result in another file

Hi Friends, Need Help. I have file1.txt as File1.txt |123|A|7267|Hyder|Cross|Sell|7801 |995|A|7051|2008|Lunar|New|Year|Promotion|7801 |996|A|7022|Q108|Targ|Prospect|&|SSCC|Savings|Promo|7801 |997|A|7182|Q1|Feb-Apr|08|Credit|ITA|PA|SBA|Campaign|7801 File2.txt... (7 Replies)
Discussion started by: i150371485
7 Replies

5. Shell Programming and Scripting

Extract Field from a file

I have an input file with content like : 18:51:18 | 217863|Acct 0110855565|RC 17608| 16 Subs| 1596 UsgRecs| 2 Secs| 430 CPUms| prmis2:26213 <MoveUsage d aemon needs to run on this account before it can be billed.> 23:03:30 | 896529|Acct 2063947620|RC 17608| 8 Subs| 148 UsgRecs| ... (9 Replies)
Discussion started by: Rajesh Putnala
9 Replies

6. UNIX for Dummies Questions & Answers

Extract a certain field from a CSV?

EDIT: This problem has been solved thanks to the help of scottn. Okay, so I have a CSV. Let's say it has the following entries in it: Jackie Chan,1954,M Chuck Norris,1930,M Bruce Lee,1940,M How would I, for example, extract the gender out of a certain person, maybe based on the year of... (12 Replies)
Discussion started by: chickeneaterguy
12 Replies

7. UNIX Desktop Questions & Answers

Extract third field of third line

Hi, how do I extract the third field of the first line? I know how to get the first line or the third field of a file, but I can't get the single entry. awk 'NR==1' file.txt awk '{print $3}' file.txt Please tell me how to combine these. And how do I set this value into a variable? ... (1 Reply)
Discussion started by: etownbetty
1 Replies

8. Shell Programming and Scripting

how to extract last occurence of the field

path = /first/second/third/fourth. i want to extract /first/second/third from path.my program something like this .... path=/first/second/third/fourth noc=`echo $path|tr '/' '\n'|wc -w` var='echo $noc|cut -d'/' -f 1-$noc --> is giving error. why $noc is not working here.any other... (3 Replies)
Discussion started by: kcp_pavan
3 Replies

9. UNIX for Dummies Questions & Answers

extract a field by logic

below are the contents of file 'tmp.out': 2|34|534| 1|355|54| 1|443|34| 3|43|768| 3|7|887| 1|9|990| How do I extract the 2nd and 3rd columns of file 'tmp.out' only when the first column equals '1'. Note that this file will be huge; atleast 5million+ rows, so I want to avoid looping... (4 Replies)
Discussion started by: ChicagoBlues
4 Replies

10. Shell Programming and Scripting

How to extract elements in a field using a number

Hi, I face difficulty where the number which I grep before I would like to use it as number to grep again in another file. For example in file 1, I extract the second field and assign to variable "char" in a while loop. And then, I grep again this char to get i and j. char=`echo "${LINE}"|... (17 Replies)
Discussion started by: ahjiefreak
17 Replies
Login or Register to Ask a Question