1

I tried fetching only the commit ID from the commit message in the shell script, I need only "d1099308a1af0f91e93bf22cf6e9b5d294cf121d"

commit_message = "commit d1099308a1af0f91e93bf22cf6e9b5d294cf121d Author: Martin Date: Wed Apr 17 16:05:35 2019"

I tried using the following sed command, but it is not working commit_ID=$( sed -e 's/commit .(*) Author/' $commit_message )

3 Answers 3

1

You mean something like that?

sed 's/^commit \([^ ]*\).*/\1/' <<< $commit_message

output

d1099308a1af0f91e93bf22cf6e9b5d294cf121d
Sign up to request clarification or add additional context in comments.

Comments

1

If you do not have other ID's, this regex will work:

[0-9a-fA-F]{20,}

If there are other ID's, then adding a look behind will help filtering:

(?<="commit\s)[0-9a-fA-F]{20,}

However, the "s" command of sed does not fetch, it "substitutes". For fetching, you may want to use "grep" or others.

Comments

0

Give a try to:

egrep -o "[a-f0-9]{40}" log.txt

This will return only the git commit ID SHA-1 hashes (40 digits long).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.