Friday, July 22, 2022

[SOLVED] How to replace matching string by its content in parentheses in shell

Issue

I'm trying to produce a shell script which is formatting commits in Shell. After making a git log, I use grep to delete useless lines and now I want to change this :

feat(my-feat): my commit

to this:

my-feat: my commit

I want to write directly in a file: git log ... | grep -v ... >> CHANGELOG.md

Do you please have an idea how to achieve this ?

Thank you.


Solution

Using sed

$ sed 's/[^(]*(\([^)]*\))/\1/' input_file > new_file
$ cat new_file
my-feat: my commit


Answered By - HatLess
Answer Checked By - Marilyn (WPSolving Volunteer)