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 -

Qt QGraphicsScene is not accessable from QGraphicsView (on Qt 5.6.1) -

What is happening when Matlab is starting a "parallel pool"? -