![]() |
|
|
|
|
|||||||
| 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 |
| Korn: How to loop through a string character by character | shew01 | Shell Programming and Scripting | 10 | 3 Days Ago 04:58 AM |
| cut from a particular character to the end of the string | grajesh_955 | Shell Programming and Scripting | 2 | 05-25-2008 03:03 AM |
| converting character string to hex string | axes | High Level Programming | 5 | 09-20-2006 10:04 AM |
| How do I get the nth character from a string? | toughman | UNIX for Dummies Questions & Answers | 4 | 06-22-2006 09:54 AM |
| Searching a string for a character | turbulence | Shell Programming and Scripting | 7 | 01-12-2006 06:56 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
how to display only last character of a string?
hi all,
if i do an: "echo $string |" what should be after the pipe to display ONLY the last char of the output? tia, DN2 |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Depends on your shell:
[zsh] Code:
zsh-4.3.4% print ${${:-string}[-1]}
g
otherwise: Code:
echo string|{ read; echo "${REPLY#${REPLY%?}}";}
|
|
#3
|
||||
|
||||
|
thnx! works perfectly fine...
|
|
#4
|
|||
|
|||
|
using sed
Code:
echo $string | sed -e 's/\(^.*\)\(.$\)/\2/' |
|
#5
|
||||
|
||||
|
thnx also...
|
|
#6
|
|||
|
|||
|
1 saved substring suffice:
Code:
sed '/.*\(.$\)/\1/' Code:
awk '{print substr($0,length,1)}'
|
|
#7
|
||||
|
||||
|
GNU Awk:
Code:
$ echo string|awk '$0=$NF' FS= g Last edited by radoulov; 01-16-2008 at 04:49 AM. |
||||
| Google The UNIX and Linux Forums |