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
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
Depends on your shell:
[zsh]
zsh-4.3.4% print ${${:-string}[-1]}
g
otherwise:
echo string|{ read; echo "${REPLY#${REPLY%?}}";}
thnx! works perfectly fine...
using sed
echo $string | sed -e 's/\(^.*\)\(.$\)/\2/'
thnx also...
1 saved substring suffice:
sed '/.*\(.$\)/\1/'
With awk:
awk '{print substr($0,length,1)}'
Regards
GNU Awk:
$ echo string|awk '$0=$NF' FS=
g
# printf $s | cut -c`printf $s | wc -c`
Or:
cut -c ${#s} <<<"$s"
or with ksh93 and bash:
$ echo ${s: -1}
g
print "${string[${#string}]}"