Friday, January 2, 2015

Get last characters of a line

Here are the two ways that we can use to get the last character of a line. 
 If you would like to get last one character then. 
 $ echo hai |tail -c 1 

 $ echo hai |tail -c 2
   i 

 
 




In linux / unix by default all most all the commands end the line with a new line and so while using the tail command we need to give -c 2 instead of -c 1. 

While using awk you can use the following syntax 

$ echo hai |awk '{print substr($0,length,1)}'
i
 
 


No comments:

Post a Comment