-2

I have this block of text'

/dev/disk0s2   3.6Ti  2.9Ti  796Gi    79% 383906083 104366287   79%   /
/dev/disk0s3   1.2Ti  1.3Ti  796Gi    79% 383906083 104366287   79%   /

using (see https://regex101.com/r/44YqQe/1)

(\/dev\/disk0s2).* (\d*\.\d+)?Ti

Desired result: 3.6

Actual Result : 2.9

Question

How do I match and stop at the first match with this regex?

Lacer
  • 5,668
  • 10
  • 33
  • 45
  • Are you using it with `sed` or similar tool? If not use `(\/dev\/disk0s2).*? (\d*\.\d+)?Ti` instead. – markalex Apr 16 '23 at 09:48
  • If bash tools are used you'll probably need something like `(\/dev\/disk0s2).* (\d*\.\d+)?Ti (\d*\.\d+)?Ti`. Or simple `(\/dev\/disk0s2)\s*(\d*\.\d+)?Ti` if it is expected that only spaces are between disk and size. – markalex Apr 16 '23 at 09:52
  • (\/dev\/disk0s2)\s*(\d*\.\d+)?Ti did it thanks! – Lacer Apr 16 '23 at 09:54

1 Answers1

1

Depending on you situation you could use one of the following solutions.

If it is expected that only spaces are between disk and size: (\/dev\/disk0s2)\s*(\d*\.\d+)?Ti.

If any symbol could be expected, and you're using tool supporting PCRE-like regexes: (\/dev\/disk0s2).*? (\d*\.\d+)?Ti. It will match first number before Ti by utilizing lazy matching.

If bash tools (like sed) are used, you'll probably need something like (\/dev\/disk0s2).* (\d*\.\d+)?Ti (\d*\.\d+)?Ti.

markalex
  • 8,623
  • 2
  • 7
  • 32