1830214 Members
1421 Online
109999 Solutions
New Discussion

modify content of file

 
SKSingh_1
Frequent Advisor

modify content of file

Hi,

I have a problem. I am using glance to take out process memory area details using one adviser file format. My query is:

How to modify process id given in adviser file:

"if PROC_PROC_ID == 2244"

mean modifying process number (2244) using sed or tr?
5 REPLIES 5
Hasan  Atasoy
Honored Contributor

Re: modify content of file

hi ;

first create a template and put ZZZZ as process id in template file ;
second ,
tr -s "ZZZZ" processid < template_file > adviser file.

third ;
give adviser_file to glance,

I hope ıunderstand truely.
SKSingh_1
Frequent Advisor

Re: modify content of file

Hi,

the problem is ZZZZ will vary and have any process id to monitor. so, I am looking for command independent of existing process id in adviser file.
Peter Nikitka
Honored Contributor

Re: modify content of file

Hi,

if you insist in not using templates:

otherpid=4711
awk -v newid=$otherpid'"' '$2=="PROC_PROC_ID" {$4=newid; print}' adviser1 >adviser2

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
James R. Ferguson
Acclaimed Contributor

Re: modify content of file

Hi"

Use Perl and you can update your adviser file "in place":

# perl -pi.old -e 'BEGIN{$pid=shift or die};s/(if PROC_PROC_ID\s*==\s*)(\d*)\b/\1$pid/' pid_value adviser

The original 'adviser' is retained as a backup called 'adviser.old'. No matter what the value of the pid in the string shown, it will be replaced with your value, passed as a first argument.

Thus in the example above, if you want a 'pid' value of 12345, pass that as the 'pid_value' and pass "adviser" (or whatever) as the filename.

Regards!

...JRF...
SKSingh_1
Frequent Advisor

Re: modify content of file

Thanks all. Got the solution.