The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Assigning variable from command outputs to shell staze Shell Programming and Scripting 2 06-28-2009 12:40 AM
Trouble with tee command to capture script outputs muthubharadwaj Shell Programming and Scripting 5 02-16-2009 08:29 PM
recording command outputs in background jehrome_rando Shell Programming and Scripting 2 02-16-2009 05:13 PM
Need help operating the "vi" command remotely Terrible UNIX for Advanced & Expert Users 4 06-13-2006 12:54 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 4 Weeks Ago
frans's Avatar
frans frans is offline
Registered User
  
 

Join Date: Oct 2009
Location: Drôme, France
Posts: 131
Quote:
Originally Posted by proactiveaditya View Post
Code:
ps -e -o pcpu,pid,cmd --sort pcpu | sed '/^ 0.0 /d'|awk '{print $2}'|grep -v PID

Gives the output:

Code:
4482
4023
5912

I want to operate on each pid in the output. How to do so.

Code:
for PID in $(ps -e -o pcpu,pid,cmd --sort pcpu | sed '/^ 0.0 /d'|awk '{print $2}'|grep -v PID)
do
    echo "the PID is $PID" # or whatever you want to do with that PID
done

Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:35 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0