Sed to remove first or last character in a string.
- July 1st, 2009
- Posted in Documentation
- Write comment
To remove the first character in a string:
echo $STRING |sed ‘s/.\(.*\)/\1/’
To remove the last character in a string:
echo $STRING | sed ‘s/\(.*\)./\1/’
To remove the last five characters in a string:
echo $STRING | sed ‘s/\(.*\)…../\1/’
To remove all whitespace at the end of the line:
echo $STRING | sed ‘s/[ ]*$//’
No comments yet.