reformat ps output


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users reformat ps output
# 1  
Old 09-23-2008
reformat ps output

I often use "ps -ef" command to list all running processes. Now i want to customize the output to show only 2 parts: CMD and UID as below:

/bin/bash /usr/bin/run-parts /etc/cron.weekly root
/usr/sbin/httpd apache
/usr/sbin/httpd apache
/usr/sbin/httpd apache


I use
Code:
ps -ef | awk '{print $8" "$1}'

, but it's not a good way because CMD part can have its arguments (aka long list of options), we can not tell awk to do like this: awk '{print $8 $9 $10 $11 .... $20 " " $1}'.

Anyone know a better way in bash shell?
Thanks

Last edited by fongthai; 09-23-2008 at 04:53 AM.. Reason: correct spelling
# 2  
Old 09-23-2008
what are UNIX OS X Developer tools that are required to run Tomcat as daemon process.

Hi All,
can any one brief me about what are the UNIX OS X Developer tools that are required to run Tomcat as daemon process.

Problem : while Compiling JSVC it needs OS X Developer tools to be installed.

Reference :Installing Apache Tomcat 6 on Mac OS X 10.5 Leopard

can i use Mac Os x developer tools for unix os x developer tool ?
# 3  
Old 09-23-2008
Code:
ps -eo command uid

the -o option allows you to specify which fields are output by ps. Consult your man page for ps for the exact format specifiers you want.
# 4  
Old 09-23-2008
hmm, -o is great, I can change to
Code:
ps -eo command,user

But if the command is long it'll be truncated.
Code:
ps -eo command:200,user

200 is a custom length for "command" can show, but we will face another issue: all commands will have a fixed length as 200 chars, the output will not clean to see. Anyway, thank you so much Jim!

Last edited by fongthai; 09-23-2008 at 06:25 AM.. Reason: add code
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to reformat output if input file is empty, but not if file has data in it

The below awk improved bu @MadeInGermany, works great as long as the input file has data in it in the below format: input chrX 25031028 25031925 chrX:25031028-25031925 ARX 631 18 chrX 25031028 25031925 chrX:25031028-25031925 ARX 632 14... (3 Replies)
Discussion started by: cmccabe
3 Replies

2. Shell Programming and Scripting

Reformat awk output

I need to rearrange the output but i am unable to arrange it to match the format. In the output i need NAME=\"To in the column . Bash: #!/bin/bash cd /cygdrive/c/output/a cat *.txt > output.txt i=/cygdrive/c/output/a/output.csv #echo "NE_Name, Source, Destination, OSPF_AREA_ID"... (4 Replies)
Discussion started by: adgjmpt
4 Replies

3. Shell Programming and Scripting

Alter awk script to reformat output

Data: 0,mfrh_green_screen,1455432969,37540,/prod/test/system/sys/unikixmain.log,3.0M,mfrh_green_screen,3120660,0,36964--37540 0,mfrh_green_screen,1455433269,38100,/prod/test/system/sys/unikixmain.log,3.1M,mfrh_green_screen,3164223,0,37540--38100... (1 Reply)
Discussion started by: SkySmart
1 Replies

4. Shell Programming and Scripting

Using awk to reformat file output

Hi there. I need to reformat a large file. Here is a sample of the file. NETIK0102_UCS_Boot_a,NETIK0102_UCS_Boot_b 5200 2438 70G 5200 2439 70G NETIK0102_UCS_HBA0_a,NETIK0102_UCS_HBA1_b,NETIK0102_UCS_HBA2_a,NETIK0102_UCS_HBA3_b 2673 19D7 55G 2673 19C0 30G 2673 19F5 120G... (5 Replies)
Discussion started by: kieranfoley
5 Replies

5. Shell Programming and Scripting

Use search pattern to reformat the output

I have below file listing ] ls -1 *.txt MISTradesReport_141105_d130240_VOLCKER_EMEA_LOANIQ_FEED_2013-12-24.txt MISTradesReport_141106_d130240_VOLCKER_NA_LOANIQ_FEED_2013-12-24.txt MISTradesReport_141107_d130240_VOLCKER_EMEA_CDS_CRDI_FEED_2013-12-24.txt... (4 Replies)
Discussion started by: krg.sati
4 Replies

6. Shell Programming and Scripting

need awk or sed help to reformat output

We have the following output: server1_J00_data_20120711122243 server1_J00_igs_20120711122243 server1_J00_j2ee_20120711122243 server1_J00_sec_20120711122243 server1_J00_data_20120711131819 server1_J00_igs_20120711131819 server1_J00_j2ee_20120711131819 server2_J00_data_20120711122245... (10 Replies)
Discussion started by: ux4me
10 Replies

7. UNIX for Advanced & Expert Users

Script to reformat output

Hi colleagues, I have the followind script. db2 -x "select substr(TBSPACE,1,20) TABLESPACE from syscat.tables where tabschema = 'SCHEMA' and tabname like '%XXXX' group by TBSPACE order by TBSPACE" | awk '{print $1}' | while read tablespace do db2 "list tablespaces show detail" |grep -p -w... (5 Replies)
Discussion started by: systemoper
5 Replies

8. Shell Programming and Scripting

Reformat a file

I have a csv file with 11 columns. The first columns contains the User Id. One User id can have multiple sub Id. The value of Sub Id is in column 10. 100026,captjason@hawaii.rr.com ,jason ,wolford ,1/16/1969, ,US, ,96761 ,15 ,seg_id 100026,captjason@hawaii.rr.com ,jason ,wolford ,1/16/1969,... (3 Replies)
Discussion started by: r_t_1601
3 Replies

9. Shell Programming and Scripting

Please help me reformat this file

I am working with a file of the form; 4256 7726 1 6525 716 1 7626 0838 1 8726 7623 2 8625 1563 2 1662 2628 3 1551 3552 3 1542 7984 ... (3 Replies)
Discussion started by: digipak
3 Replies

10. Shell Programming and Scripting

reformat the output from "diff" command

Hi all, I use the diff command and got the output: $> diff -e file1.txt file2.txt 15a 000675695 Yi Chen Chen 200520 EASY 50 2/28/05 0:00 SCAD Debit Card Charge . 12a 000731176 Sarah Anderson 200520 EASY 25 2/28/05 0:00 SCAD Debit Card Charge . 11a... (5 Replies)
Discussion started by: CamTu
5 Replies
Login or Register to Ask a Question