Printing String Backward

How can I cut the process time (201) from the above process line? I did the following ..but unsuccess.
ProcTime=`echo $txtline|awk -F" " '{print($11)}'|awk -F":" '{print($1)}'`
b'cos sometimes I get the following for today's or fresh processes -
root 12797 1 TS 70 0 12:58:46 pts/7 01:01 mfe4ppm klP410 34
In this case I want to have 01 processor time.
 

Test for the number of words in your txtline variable. Something like:
if there are 13 words in the line, print out the 10th field else if there are 12 words in the line, print out the 9th field. Pretty simple to implement.
 

Word 9 or word 10 will be the process time, so you can grab the one that contains a colon. All 3 solutions below grab word 9 or 10, but then each takes a different approach on how to get the minutes only and not the seconds.

echo $txtline |
awk '{$0=(match($10,":"))?$10:$9;FS=":";print $1}' |
read ProcTime
echo "ProcTime=$ProcTime"

echo $txtline |
awk '{x=(match($10,":"))?$10:$9;y=substr(x,1,index(x,":")-1);print y}' |
read ProcTime
echo "ProcTime=$ProcTime"

echo $txtline |
awk '{x=(match($10,":"))?$10:$9;sub(":"," ",x);print x}' |
read ProcTime ProcSec

The first solution changes the field separator to a colon to print the minutes.

The second solution pulls the minutes from the processing time by using substring function.

The third solution puts processing time into variable x and changes the colon to a space. Since x prints as two words, the read statement following awk must read into two variables. If you read into just one variable, both words would go into that one.

See Also
Unix Administrator Career Path

Have a Unix Problem
Do you have a UNIX Question?

Unix Books :-
UNIX Programming, Certification, System Administration, Performance Tuning Reference Books

Return to : - Unix System Administration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.
The site www.gotothings.com is in no way affiliated with or endorsed by any company listed at this site.
Any unauthorised copying or mirroring is prohibited.