Hi Can someone help me with this one?
I have string..
(PROC_PROC_ID == 12183) <--PID is dynamic
and i want to replace the PID number with whatever PID from
/opt/hpws/apache32_2/logs/httpd.pid file.
i'm having problem since the PID on the string is dynamic. It may be 2-5 digits or more.
The PID is only string the numbers to the file i want to replace
from this you will get the PID.. whatever may be its length.. then do the replacement
echo "(PROC_PROC_ID == 12183)"|awk -F"[==)]" '/PROC_PROC_ID/{print $3}'
rdcwayx
3
PROC_PROC_ID = $(echo /opt/hpws/apache32_2/logs/httpd.pid)
thanks vidyar! your solution is working.. btw is there anyway i can replace it directly using sed?
here's the complete parm file
PROCESS LOOP
{
//Get PID
if (PROC_PROC_ID == 12183) then
{
//Start Processing
PRINT "PROCESS: ",PROC_PROC_NAME,
" PID: ",PROC_PROC_ID,
" CPU: ",PROC_CPU_TOTAL_UTIL," %",
" MEM: ",PROC_MEM_RES,
" THREAD: ",PROC_THREAD_COUNT
}
}
I'm trying to replace it with
sed "s|PROC_PROC_ID \=\= [0-9]+|PROC_PROC_ID \=\= $PID|" parm.file
but it doesn't seem to work
This one will work but unfortunately it won't be always a 5-digit number
sed "s|PROC_PROC_ID == [0-9]\{5\}|PROC_PROC_ID == $PID|" parm.file
echo "(PROC_PROC_ID == 12183)" | sed 's/\(PROC_PROC_ID ==\).*/\1 whatever you want here)/g'
mo@mo-laptop:~/scripts$ echo "(PROC_PROC_ID == 12183)" | sed 's/\(PROC_PROC_ID ==\).*/\1 whatever you want here)/g'
(PROC_PROC_ID == whatever you want here)
mo@mo-laptop:~/scripts$