My problem
I have a file with items, one per line. The item contains at least one dash, and I would like to remove the last dash and the words that follow. For example:
item asdkalqndla-asdnkfsv-324we-blueray
item asda-vbght564e-dfg-redapple
item gefdsc-fgy-543-5trr-floatingvanilla
Should give:
item asdkalqndla-asdnkfsv-324we
item asda-vbght564e-dfg
item gefdsc-fgy-543-5trr
What have I tried
sed 's/\-.*$//' lines.txt
Which gives
item asdkalqndla
item asda
item gefdsc
Because the regex is greedy, and consumes everything from the first dash onwards.
My question
How can I remove all characters from the last -
in a string till EOL?