hi, i would like to extract the header and put it in a variable, then use printf to output the variable, but i keep on getting errors...please tell me if my format is incorrect.
HDR = "`ps -e -o user,pid,ppid,pcpu,stime,etime,time,comm | head -n 1`"
printf (%s, $HDR);
thanks!
I figured out why i got the message for "invalid format character" for the string i'm trying to print. The string procuded by the command contains "%CPU", and it doesn't seem to like the "%" in the middle of the string. Is there any way to make the whole string prints including "%" using printf?
Thank you much.
You can escape the % by using %% instead (to print a literal %).
Change your code to
HDR=`ps -e -o user,pid,ppid,pcpu,stime,etime,time,comm | head -n 1 | sed 's/%/%%/g'`
printf "%s" HDR
This code is for bash/ksh
Cheers
ZB
Thank you thank you thank you!
happy friday! 