![]() |
|
|
|
|
|||||||
| 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 |
| search from specified charactor space | akmix | UNIX for Dummies Questions & Answers | 6 | 01-30-2008 08:51 PM |
| Pick the exact value | ahmedwaseem2000 | Shell Programming and Scripting | 11 | 01-22-2008 08:06 AM |
| how to pick distinct records.......... | ss4u | UNIX for Dummies Questions & Answers | 3 | 01-03-2007 11:39 PM |
| Please help me pick a machine | Gnfanatic | SUN Solaris | 11 | 04-11-2006 11:06 AM |
| insert escape charactor within VIM | cin2000 | Shell Programming and Scripting | 2 | 03-23-2006 09:46 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
how to pick out last charactor of a string?
Hi,
Does anyone know how many ways to pick out last charactor of a string? Thanks! |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
What shell?
|
|
#3
|
|||
|
|||
|
pick up last charactor from string
I am using ksh for this program.
But I'd also like to know if there is more than one way to do it. Even maybe using awk, sed, perl.... Thanks a lot! |
|
#4
|
||||
|
||||
|
Code:
#!/bin/ksh
a='123'
echo "${a#${a%?}}"
# OR
echo "${a}" | sed 's/.*\(.\)/\1/'
# OR
echo "${a}" | nawk '{print substr($0, length($0))}'
|
|
#5
|
||||
|
||||
|
Or...
Code:
expr "${a}" : '.*\(.\)'
|
|
#6
|
||||
|
||||
|
Code:
echo "${a}" | tail -2c
Cheers ZB |
|
#7
|
|||
|
|||
|
One more..
echo $a | cut -c${#a} |
|||
| Google The UNIX and Linux Forums |