Extracting one column from a ps -ef command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting one column from a ps -ef command
# 1  
Old 03-31-2005
Extracting one column from a ps -ef command

Hi,

I want to extract one value/column from a ps -ef command. Here's an example of the output:

mqm 14552 1 0 15:48:43 - 0:00 amqpcsea SWNETTQ1
mqm 57082 1 0 15:48:42 - 0:00 amqpcsea SWNETDQ1
mqm 88104 1 0 15:26:37 - 0:00 amqpcsea SWNETEQ1
mqm 90196 1 0 16:03:56 - 0:00 amqpcsea SWNETTQ2

I want to display only the last column like this

SWNETTQ1
SWNETDQ1
SWNETEQ1
SWNETTQ2


I can do this using the following command but it seems a bit cumbersome:

ps -ef|grep sea|grep -v grep|cut -f2 -d"-"|cut -f2 -d":"|cut -f3 -d" "

Anyone know of a better way to do this? I've tried awk but have only managed to get them displayed on the same line

thanks

Gareth
# 2  
Old 03-31-2005
ps -ef | nawk '/sea/ { print $NF}'
# 3  
Old 03-31-2005
also works ...
Code:
ps -ef | awk '/sea/ {print $NF}'

# 4  
Old 04-01-2005
thanks for those, they both worked a treat although I did still need to keep the greps in there otherwise the results were like this:

awk
===
# ps -ef | awk '/sea/ {print $NF}'

SWNETTQ1
$NF}
SWNETDQ1
SWNETEQ1
SWNETTQ2

# ps -ef |grep sea| awk '/sea/ {print $NF}'

SWNETTQ1
sea
SWNETDQ1
$NF}
SWNETEQ1
SWNETTQ2

nawk
====
# ps -ef | nawk '/sea/ {print $NF}'

SWNETTQ1
SWNETDQ1
$NF}
SWNETEQ1
SWNETTQ2

ps -ef |grep sea| nawk '/sea/ {print $NF}'

SWNETTQ1
SWNETDQ1
$NF}
sea
SWNETEQ1
SWNETTQ2

However, including (and adjusting) the greps removed the erroneous entries.
# ps -ef |grep amqpcsea|grep -v grep| awk '/sea/ {print $NF}'

SWNETTQ1
SWNETDQ1
SWNETEQ1
SWNETTQ2


Thanks again
# 5  
Old 04-01-2005
this may work as well ...
Code:
ps -ef | awk '/sea/ && $NF !~ /\$/ {print $NF}'

# 6  
Old 04-02-2005
Code:
ps -ef|grep sea|grep -v grep|cut -d" " -f 9

# 7  
Old 04-02-2005
Quote:
Originally Posted by bhargav
Code:
ps -ef|grep sea|grep -v grep|cut -d" " -f 9


ps -ef|grep [s]ea|cut -d" " -f 9
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

FORTRAN program to extracting column

Dear folks I have a large data set which contains 400K columns. I decide to select 50K determined columns from the whole 400K columns. Is there any suggested fortran program which could do this process for me? I need to also mention that I store all of the columns id in one file which may help... (1 Reply)
Discussion started by: sajmar
1 Replies

2. Shell Programming and Scripting

Extracting the column containing URL from a text file

I have the file like this: Timestamp URL Text 1331635241000 http://example.com Peoples footage at www.test.com,http://example4.com 1331635231000 http://example1.net crack the nuts http://example6.com 1331635280000 http://example2.net ... (3 Replies)
Discussion started by: csim_mohan
3 Replies

3. Shell Programming and Scripting

Parsing a column and extracting subsets

Please help with this.. my file sizes exceed 40GB,,not possible to do manually. I have a string in the 2nd column that has strings like 5M108N31M, 3S2M100N45M4S etc..the first column is a number. There can be 0,1 or 2 number of S but only 1,2 Ms and only 1 N. S only occurs at the... (4 Replies)
Discussion started by: ritakadm
4 Replies

4. Shell Programming and Scripting

Help with File processing - Extracting the column

I have a line from table space report: 5 135_TT ms Normal 1774336.0 1774208.0 761152.0 1013056.0 57.1% Now I have to get 1013056.0 as o/p. For this I tried cut -f32 -d" " previously it worked now it is showing empty space. Suggest me the best code for this which... (1 Reply)
Discussion started by: karumudi7
1 Replies

5. Shell Programming and Scripting

Extracting rows with a certain column

Hi, I want to extract rows that have specific characters at a certain column. It might be best to show you my problem. So my tab delimited file looks like this: YPR161C 10 16 864445 866418 - Verified 3.558 YOL138C 6 15 61325 65350 - Verified 0.6... (1 Reply)
Discussion started by: phil_heath
1 Replies

6. UNIX for Dummies Questions & Answers

Extracting the last column of a text file

I would like to extract the last column of a text file but different rows of the text file have different numbers of columns. How do I go about doing that? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

7. Shell Programming and Scripting

extracting a column using search term

I am trying to select a column using a search term. My input file looks like this (tab delimited): ABC BJS FDG GHH DGH DFG GHF 95 456 5 266 87 4567 67 3 54 678 4567 45 6 36 232 55 3 5 6 8 34 cat filename | awk '{print $2}'above code will give me the second column. However, what I want... (2 Replies)
Discussion started by: SangLad
2 Replies

8. Shell Programming and Scripting

Extracting column value from perl

Hello Kindly help me to find out the first column from first line of a flat file in perl I/P 9869912|20110830|00000000000013009|130|09|10/15/2010 12:36:22|W860944|N|00 9869912|20110830|00000000000013013|130|13|10/15/2010 12:36:22|W860944|N|00... (5 Replies)
Discussion started by: Pratik4891
5 Replies

9. UNIX for Advanced & Expert Users

extracting/copy a column into a new column

Hello, Anybody out there knows how to copy a column data into a blank column using unix command? Thanks (1 Reply)
Discussion started by: folashandy
1 Replies

10. Shell Programming and Scripting

Extracting a column using AWK

Hi, I've a text file like ABC,,100 A,100,200 In the above example, I have 3 columns. I want to extract the second column. I'm expecting a value like 100 i.e first record will not have any value but still it has to give me null value. second record should give 100. Can anybody... (2 Replies)
Discussion started by: ronald_brayan
2 Replies
Login or Register to Ask a Question