How do you remove the last two characters in UNIX?

How do you remove the last two characters in UNIX?
Answer
I have two solutions :
  1. cut: echo “somestring1” | rev | cut -c 2- | rev. Here you reverse the string and cut the string from 2nd character and reverse again.
  2. sed : echo “somestring1” | sed ‘s/.$//’
 

Tìm kiếm

Back
Top