editting file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting editting file
# 1  
Old 11-26-2007
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.
# 2  
Old 11-26-2007
Quote:
Originally Posted by sharif
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.Smilie
# 3  
Old 11-26-2007
editting file

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

output is like this:
654145831789025902
# 4  
Old 11-26-2007
Code:
sed 's/ /\
/g' filename | while read pid
do
ps -ef | grep "$pid"
done > output.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script (sh file) logic to compare contents of one file with another file and output to file

Shell script logic Hi I have 2 input files like with file 1 content as (file1) "BRGTEST-242" a.txt "BRGTEST-240" a.txt "BRGTEST-219" e.txt File 2 contents as fle(2) "BRGTEST-244" a.txt "BRGTEST-244" b.txt "BRGTEST-231" c.txt "BRGTEST-231" d.txt "BRGTEST-221" e.txt I want to get... (22 Replies)
Discussion started by: pottic
22 Replies

2. Shell Programming and Scripting

Compare 2 text file with 1 column in each file and write mismatch data to 3rd file

Hi, I need to compare 2 text files with around 60000 rows and 1 column. I need to compare these and write the mismatch data to 3rd file. File1 - file2 = file3 wc -l file1.txt 58112 wc -l file2.txt 55260 head -5 file1.txt 101214200123 101214700300 101250030067 101214100500... (10 Replies)
Discussion started by: Divya Nochiyil
10 Replies

3. Shell Programming and Scripting

Editting a record

robert (6 Replies)
Discussion started by: robert89
6 Replies

4. Linux

Problem editting the first occurence of a pattern in the first uncommented line

Hi I have to replace a pattern found in the first uncommented line in a file. The challenge I'm facing is there are several such similar lines but I have to edit only the first uncommented line. Eg: #this is example #/root/xyz:Old_Pattern /root/xyz:Old_Pattern /root/xyz:Old_Pattern ... (10 Replies)
Discussion started by: Stoner008
10 Replies

5. Shell Programming and Scripting

Match list of strings in File A and compare with File B, C and write to a output file in CSV format

Hi Friends, I'm a great fan of this forum... it has helped me tone my skills in shell scripting. I have a challenge here, which I'm sure you guys would help me in achieving... File A has a list of job ids and I need to compare this with the File B (*.log) and File C (extend *.log) and copy... (6 Replies)
Discussion started by: asnandhakumar
6 Replies

6. Shell Programming and Scripting

Editting each line in a file

Hi Can anyone please help me in resolving my issue. I have a file with entries like this t9787ms 99970 22/08/2010 12:30 /www.google.com t9788ms 99942 22/08/2010 12:40 /www.google.com t4788ms 88942 22/08/2010 01:40 /www.google.com there are around 5 lakh records of this type my requirement... (4 Replies)
Discussion started by: mskalyani
4 Replies

7. UNIX for Dummies Questions & Answers

matching IDs from two files and editting

I have two files. One has: ID# 0 a b c d e f g h i j k....................~2 milion columns ID# 0 l m n o p q r s t u v....................~2 milion columns . . . ~6000 lines Other has: ID# 1 or ID# 2 . . ~6000 lines (2 Replies)
Discussion started by: polly_falconer
2 Replies

8. Shell Programming and Scripting

Unix file editting commands

ok, are there any other file editting commands out there other than the below that comes with sunsolaris & linux vi, emacs, ed, (1 Reply)
Discussion started by: Terrible
1 Replies

9. Shell Programming and Scripting

file editting with shell programmin

Hello, I have several handreds of text files. The format of file looks like: column1 column2 column3 column4 column5 id1 definition1 name1 fieldid comm1 id2 definition2 name2 fieldid ... (4 Replies)
Discussion started by: ssshen
4 Replies
Login or Register to Ask a Question