Skip to content
Advertisement

Using cut to remove until a delimiter from end

I have a string with many delimiters like :

abcd – efgh – foobar.extension (Delimiter ‘-‘)

I want to remove the

JavaScript

So far, I have done

JavaScript

But this does not help as it echo’s

JavaScript

I want to be able to keep the inital part before the final delimiter(‘-‘) is found.

Advertisement

Answer

In bash you can use this built-in string manipulation:

JavaScript

"${a% -*}" will remove any part of $a starting with a space followed by -, from end of the string.

Or using sed:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement