how to pick out last charactor of a string?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to pick out last charactor of a string?
# 1  
Old 12-20-2005
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!
# 2  
Old 12-20-2005
What shell?
# 3  
Old 12-20-2005
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  
Old 12-20-2005
Code:
#!/bin/ksh

a='123'
echo "${a#${a%?}}"

# OR
echo "${a}" | sed 's/.*\(.\)/\1/' 

# OR
echo "${a}"  | nawk '{print substr($0, length($0))}'

# 5  
Old 12-20-2005
Or...
Code:
expr "${a}" : '.*\(.\)'

# 6  
Old 12-20-2005
Smilie - or....
Code:
echo "${a}" | tail -2c

BTW - it's -2c as there's a trailing newline too.....

Cheers
ZB
# 7  
Old 12-21-2005
One more..

echo $a | cut -c${#a}
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pick systems

looking for any advise on how to export Pick data from an AIX implementation. i have someone with limited experience that knows how to create a text file from a pick database. (1 Reply)
Discussion started by: jgt
1 Replies

2. Shell Programming and Scripting

Insert one charactor multiple times in VI

Hi Gurus, I forgot the command which can insert one character multiple times. for example: I need 50 "#" #############... I used the command before, it is very convenient. anybody can help this. thanks in advance. (1 Reply)
Discussion started by: Torhong
1 Replies

3. Shell Programming and Scripting

How to check charactor in certain position?

Hi Gurus, I need to check the charactor in certain position. in my file abcdef1234gh ac1234eeeegt acdead1235gh I want to check what is check from position 7 to 10's charactor, if it is 1234, then output the whole line. for above file, I want to get below output abcdef1234gh... (2 Replies)
Discussion started by: ken6503
2 Replies

4. Shell Programming and Scripting

Pick and print

Hi Friends, I'm facing an issue. I am having a file as under : a1 b1 c1 a2 a3 a4 b4 a5 b5 and I need to get the output as under: a1 b1 a4 b4 a5 b5 i.e. to pick the columns where a and b are consecutive and ignoring rest. I was trying some thing sily as: (2 Replies)
Discussion started by: vanand420
2 Replies

5. Shell Programming and Scripting

Split string with blancs to pick up information in a file ?

Hello, I am quite new in shell, and would like to pick up information in a file. The file structure is like this faor all data: T 50 2 2.5 is this a candy number color price I know how to pick up a line. I do this: head -linenumber candyfile.doc | tail -1 But I would... (6 Replies)
Discussion started by: shadok
6 Replies

6. Shell Programming and Scripting

pick columns

I want to be able pick columns from 2 files with similar reference data: File 1 Last NameFirst NameSalaryCityDunnJohn $42,000.00 ChicagoGrantSuzy $95,000.00 GaryLoweMike $80,000.00 MilwaukeeGrantMike $59,000.00 JolietLoweKaren $48,000.00 South BendFile 2 TitleFirst NameLast... (2 Replies)
Discussion started by: sigh2010
2 Replies

7. UNIX for Dummies Questions & Answers

search from specified charactor space

Hello, I'm quite a noobie in programming in UNIX and I was wondering if it is possible to use 'grep' or similar method to find PATTERNS from designated location (of charactor) for example |param 1 ||param2 | andrew kim josh daniel kim michelle michelle andrew kim I hope... (6 Replies)
Discussion started by: akmix
6 Replies

8. Shell Programming and Scripting

Pick the exact value

Hi, How do i pick a particular value from a group of lines using python. for instance from the below sample. How do I pick Value=1 of OuterLines=1 and InnerLine=1 (11 Replies)
Discussion started by: ahmedwaseem2000
11 Replies

9. Solaris

Please help me pick a machine

Hey guys I am new here and like this forum alot. I went to get into Solaris and would like to buy a sun box on ebay. NON rackmount. Problem is there is so many diff types. I am looking for one under the $800 range that can support solaris 10 and have the basics and decent ram. Can you guys... (11 Replies)
Discussion started by: Gnfanatic
11 Replies

10. Shell Programming and Scripting

insert escape charactor within VIM

Hi, I need to send "^[" command to the buffer. I tried to use insert within VIM and press 'ctrl' key and then '^' and '[' key. but it didn't work. Does anyone know how to do it? Thanks a lot! Julie (2 Replies)
Discussion started by: cin2000
2 Replies
Login or Register to Ask a Question