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

Popular posts from this blog

angular - DownloadURL return null in below code -

python 2.7 - Given three nested dictionaries, sort the top two nested dictionaries from a value in the innermost dictionary? -