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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Reading a file and writing the file name to a param file. thebeginer UNIX for Advanced & Expert Users 1 10-05-2007 01:38 PM
Unix file editting commands Terrible Shell Programming and Scripting 1 12-26-2006 02:54 PM
Reading file names from a file and executing the relative file from shell script anushilrai Shell Programming and Scripting 4 03-10-2006 02:25 AM
file editting with shell programmin ssshen@mit.edu Shell Programming and Scripting 4 07-11-2005 12:28 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 11-26-2007
Registered User
 

Join Date: Feb 2007
Posts: 36
editting file

Hi,
I am having sequence of process ids in one file.
My file contents is (Output of fuser someobject.so).

654 14583 17890 25902

This no. of processes may vary depends up on the object.


I want to check all the processes one by one. If i want to apply egrep, I need to edit this file in the follownig format. Please guidme me to do this.

654|14583|17890|25902 or with newline character. (To give this pattern as pattern file grep -f).

Regards,
Sharif.
Reply With Quote
Forum Sponsor
  #2  
Old 11-26-2007
Registered User
 

Join Date: Feb 2007
Location: Pune, Dehradun (INDIA), Michigan(US)
Posts: 187
Quote:
Originally Posted by sharif View Post
Hi,
I am having sequence of process ids in one file.
My file contents is (Output of fuser someobject.so).

654 14583 17890 25902

This no. of processes may vary depends up on the object.


I want to check all the processes one by one. If i want to apply egrep, I need to edit this file in the follownig format. Please guidme me to do this.

654|14583|17890|25902 or with newline character. (To give this pattern as pattern file grep -f).

Regards,
Sharif.
Hey,

You can use:

cat x.txt | tr -dc "[:digit:]\n" > outputfile.txt

Say in x.txt you have all the process ids.
In outputfile.txt you'll get only the digits (process ids.) and then this file you can use to check the status of processes in loop.
as:

cat outputfile.txt | \
while read line
do
ps -ef | grep "$line" >> statusfile.txt

done



Thanks.
Reply With Quote
  #3  
Old 11-26-2007
Registered User
 

Join Date: Feb 2007
Posts: 36
editting file

Hi your command is working, but the outputfile.txt is having the output without newline character.

output is like this:
654145831789025902
Reply With Quote
  #4  
Old 11-26-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,610
Code:
sed 's/ /\
/g' filename | while read pid
do
ps -ef | grep "$pid"
done > output.txt
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:17 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0