That is, going from ABCD
-> ABC
views:
65answers:
2
+8
A:
You can try:
sed s'/.$//'
The regex used is .$
.
is a regex meta char to match anything (except newline)$
is the end of line anchor.
By using the $
we force the .
to match the last char
This will remove the last char, be it anything:
$ echo ABCD | sed s'/.$//'
ABC
$ echo ABCD1 | sed s'/.$//'
ABCD
But if you want to remove the last char, only if its an alphabet, you can do:
$ echo ABCD | sed s'/[a-zA-Z]$//'
ABC
$ echo ABCD1 | sed s'/[a-zA-Z]$//'
ABCD1
codaddict
2010-09-09 09:05:19
That works...thanks!
Roger Moore
2010-09-09 09:09:44
Your explanation is much appreciated...thank you!
Roger Moore
2010-09-09 09:25:32
+2
A:
you don't have call external commands if you are using a shell, eg bash/ksh
s="ABCD"
echo ${s/%?/}
ghostdog74
2010-09-09 22:49:58