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

Is there a better way to structure post methods in Class Based Views -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -