string in reverse

Can we print any string in reverse order?

For example:
oracle 16294 1 0 Aug 11 ? 0:00 ora_reco_crepd
oracle 16276 1 0 Aug 11 ? 0:19 ora_dbw0_crepd

I need second last column from this output. (0:00 & 0:19).
I can use awk print $2 after reversing the string.

Can anyone help me?

Malay

Why dont you use this

awk '{ print $(NF-1) }'

It gives

echo "oracle 16294 1 0 Aug 11 ? 0:00 ora_reco_crepd" | awk '{ print $(NF-1) }'

But then there is a small flaw with this awk approach.

Say the sample is

26264 pts/1    S      0:16 java -jar oc4j.jar

then

echo "26264 pts/1    S      0:16 java -jar oc4j.jar" | awk '{ print $(NF-1) }'

gives

-jar

Your listing is a ps listing, I believe.

You might as well use the following

ps -eo pid,time

Look at man ps

vino

Thanks very much. Its done.

Malay

Can anyone correct my syntax?
I am trying toexecute this command from Unix prompt but not receiving any out put.

echo "oracle 15799 1 0 Oct 14 ? 2:04 oraclecrepd (LOCAL=NO)" | awk 'BEGIN {
cnt=1
for (i=NF; i>0; --i)
{
if(cnt == 3)
print $i
cnt++
}
}'

Malay

Your problem is the BEGIN. Just get rid of that. Then it prints "2:04". Another way to print the field which is 3rd from the end: awk '{ print $(NF-2) }'