I have a string like that:
And i want to get a new string called in someway (like string2) with the original string without the two | at the start and at the end of it
so that i will have this
is that possible in bash?
You can do
Or if your string length is constant, you can do
Also, this should work
Here's a solution that is independent of the length of the string (bash):
You can also use sed to remove the | not just referencing the symbol itself but using positional references as in:
Where ':' are the delimiters (you can replace them with / or any character not in the query, any sign following the s will do it) Here ^ (caret) means at the beginning of the input string and $ (dollar) means at the end. The . (point) that it's after the caret and the one that it's before the dollar sign represents a single character. So in other words we are deleting the first and last characters. Take in mind this will delete any characters even if | it's not present in the string.
Going off a few posts listed here it seems the simplest way to do it is:
edit: works on ubuntu with bash 4.2; does not work on centOS with bash 4.1