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 -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -