Issue
So I'm basically reading the first line from a file and I want the first and last characters to be trimmed but only if they are equal to a certain character. I'm looking to remove "{" and "}" from a string but ONLY IF THEY ARE THE FIRST AND LAST CHARACTERS RESPECTIVELY.
Input:
{Some_random_data_here, {more data here}, test}
Output:
Some_random_data, {more data here}, test
Here's the full command I'm using which is able to remove the first one but not the last one.
$(head -n 1 "$filePath" | sed s/^{//;s/}$//)
Solution
Your solution worked when I tested it, I only had to escape the ;
.
$ echo '{Some_random_data_here, {more data here}, test}' | sed s/^{//\;s/}$//
Some_random_data_here, {more data here}, test
Answered By - PaulProgrammer Answer Checked By - Robin (WPSolving Admin)