Want to remove last character from a string in Linux, We can do this with help of SED commands.
Use this
a) Remove last char
sed 's/.$//' input
or
sed 's/.\{1\}$//' input
i.e. -
echo 123456 | sed 's/.$//'
12345
echo 123456 | sed 's/.\{1\}$//'
12345
b) Remove last 2 char
sed 's/..$//' input
or
sed 's/.\{2\}$//' input
i.e. -
echo 123456 | sed 's/..$//'
1234
echo 123456 | sed 's/.\{2\}$//'
1234
c) Remove more char from last
sed 's/.\{n\}$//' input
where n = no of char
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiu-yxAotfIYVbU6RQs8yw-5E3T1XrlNnXsWGo1eylEgkCl7SZ6KrQrTNLDkrjIKQMse_3UHevhxCSKCE88S6d4NfrH8J-DvNHFNd9AibW1iPANovbQyv-Go3Ud2aKPob8LG7Rxb4lO_Ug/s1600/blog_logo.png)
No comments :
Post a Comment