print upto second last character in unix
If you are using BASH then it is fairly straight forward to remove last character:
s="string1,string2,"echo "${s%?}"
?
matches any single character and %?
removes any character from right hand side.
That will output:
string1,string2
Otherwise you can use this sed
to remove last character:
echo "$s" | sed 's/.$//'string1,string2
You can do it with bash
"parameter substitution":
string=12345new=${string:0:$((${#string}-1))}echo $new1234
where I am saying:
new=${string:a:b}
where:
a=0 (meaning starting from the first character)
and:
b=${#string} i.e. the length of the string minus 1, performed in an arithmetic context, i.e. inside `$((...))`