shell - print upto second last character in unix -
if length of string 5 how can print upto 4th character of string using shell scripting.i have stored string in variable , length in other variable.but how can print upto length -1.
if using bash straight forward remove last character:
s="string1,string2," echo "${s%?}"
?
matches single character , %?
removes character right hand side.
that output:
string1,string2
otherwise can use sed
remove last character:
echo "$s" | sed 's/.$//' string1,string2
Comments
Post a Comment