I am trying to remove the text between the first and last slash of a string using sed. This is what I was able to come up with using regular expressions with an online regex tester:
(?<=\/)(.*)(?=\/[a-zA-Z])
and this is the sed command:
echo "1stFolder/2ndFolder/3rdFolder/file" | sed 's/(?<=\/)(.*)(?=\/[a-zA-Z])//'
However it is not working with sed. Basically I am trying to get these outputs:
Test Case: 1stFolder/2ndFolder/3rdFolder/file
Output: 1stFolder/file
Test Case: 1stFolder/3rdFolder/file
Output: 1stFolder/file
Test Case: 1stFolder/file
Output: 1stFolder/file
I want to use sed or any shell command to get the text between the first and last slash of these filepaths removed.