1

I have a text file with a line among others:

Submitting job with ID: 50fd2805-6fcc-4bc6-91a2-638528180ab6

(It's a full line, and it has other lines before and after.)

I need to find and extract to a variable the ID. I came up with a RexEx pattern:

[\da-f]{8}(-[\da-f]{4}){3}-[\da-f]{12}

The patterns should work, but it doesn't seem to work in Shell with anything I tried: grep, sed – whatever.

One of my attempts was this:

JOB_ID=$(grep '[\da-f]{8}(-[\da-f]{4}){3}-[\da-f]{12}' file)

To be clear, as a result I need JOB_ID to contain string "50fd2805-6fcc-4bc6-91a2-638528180ab6" (without quotes.)

I'm sorry for such a seemingly noob question, but I couldn't find anything on the internet: I've read dozens of similar questions on SO and SE, and googled several tutorials, and still couldn't figure out the answer.

Any guidance is appreciated!

lazarevzubov
  • 1,767
  • 2
  • 14
  • 24
  • No, it doesn't. The pattern is OK, it works in other environments. But I can't put it into use in a Shell script. So, perhaps I need another Shell command, or parameters, or to use some special format in the pattern – I don't know and seek for guidance. – lazarevzubov Feb 08 '23 at 12:19
  • @lazarevzubov Does `grep '[0-9a-f]\{8\}\(-[0-9a-f]\{4\}\)\{3\}-[0-9a-f]\{12\}'` work better? – Biffen Feb 08 '23 at 13:02
  • @Biffen I tried to escape braces, it didn't help. – lazarevzubov Feb 08 '23 at 14:43

1 Answers1

1

You could use awk to print the last field on a line starting Submitting like this:

JOB_ID=$(awk '/^Submitting/ {print $NF}' file)
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432