Home > database >  grep for a string from URLs of different lengths
grep for a string from URLs of different lengths

Time:11-23

I have a text file (foo.txt) containing a number of URLs. Each URL contains a file ID:

www.url.com/etc/one/two/72f66_59875c1ffb57b5992-b18/something/maybe/
www.url.com/etc/8823cd1-ab9532a5dc74cc904cc6bd3e2/perhaps/
www.url.com/etc/something/8407fb_80bbb9c0d/1/2/6/

My expected output is just the file IDs:

72f66_59875c1ffb57b5992-b18
8823cd1-ab9532a5dc74cc904cc6bd3e2
8407fb_80bbb9c0d

I don't yet completely understand how to leverage grep to make this happen. I have been humbled.

Please halp.

CodePudding user response:

Those look like all hex digits, so

grep -oE '/[[:xdigit:]_-]{15,}/' foo.txt  | tr -d /
  • Related