The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Reverse FTP ganesh123 Shell Programming and Scripting 4 02-22-2007 10:20 AM
shell program to reverse the string saikiran Filesystems, Disks and Memory 1 08-29-2006 04:57 AM
reverse string manipulation senthilk615 Shell Programming and Scripting 1 03-29-2006 02:25 PM
Reverse * azmathshaikh Shell Programming and Scripting 2 04-26-2005 04:40 AM
Reverse Display marcose UNIX for Dummies Questions & Answers 5 02-12-2002 06:25 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-18-2005
Registered User
 

Join Date: May 2005
Posts: 54
Stumble this Post!
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
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 10-18-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,659
Stumble this Post!
Why dont you use this

Code:
awk '{ print $(NF-1) }'
It gives

Code:
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

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

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

Code:
-jar
Your listing is a ps listing, I believe.

You might as well use the following

Code:
ps -eo pid,time
Look at man ps

vino
Reply With Quote
  #3 (permalink)  
Old 10-18-2005
Registered User
 

Join Date: May 2005
Posts: 54
Stumble this Post!
Wink

Thanks very much. Its done.

Malay
Reply With Quote
  #4 (permalink)  
Old 10-18-2005
Registered User
 

Join Date: May 2005
Posts: 54
Stumble this Post!
Unhappy

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
Reply With Quote
  #5 (permalink)  
Old 10-18-2005
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,444
Stumble this Post!
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) }'
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:30 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0