![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Reverse FTP | ganesh123 | Shell Programming and Scripting | 4 | 02-22-2007 11: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 07:25 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Why dont you use this
Code:
awk '{ print $(NF-1) }'
Code:
echo "oracle 16294 1 0 Aug 11 ? 0:00 ora_reco_crepd" | awk '{ print $(NF-1) }'
Say the sample is Code:
26264 pts/1 S 0:16 java -jar oc4j.jar Code:
echo "26264 pts/1 S 0:16 java -jar oc4j.jar" | awk '{ print $(NF-1) }'
Code:
-jar You might as well use the following Code:
ps -eo pid,time vino |
|
#3
|
|||
|
|||
|
Thanks very much. Its done.
Malay |
|
#4
|
|||
|
|||
|
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 |
|
#5
|
||||
|
||||
|
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) }'
|
||||
| Google The UNIX and Linux Forums |