1

I'm parsing some mac OSX log files, and have come across the output of the df -h command, which I now need to split. The line looks like:

Filesystem     Size   Used  Avail Capacity iused      ifree %iused  Mounted on

Now I can't just split on the space character, as there's a space in Mounted on, but I need to split this into the nine fields.

I've tried using \s{2,} to split only on multiple spaces, but then there are single spaces between the Avail and Capacity fields, so I'm bit lost as to how to handle this.

Any suggestions would be greatly appreciated.

2
  • It looks like fixed-width csv data. See stackoverflow.com/questions/11365466/… Commented Dec 18, 2020 at 12:29
  • There is no search thing a "fixed width CSV". It is either Fixed width or CSV. Commented Dec 18, 2020 at 12:38

1 Answer 1

1

It seems that Mounted can be on and off right?

you can use it like:

((Mounted .+?)|.+?)(\s+|$)

DEMO

You may also just split it with space \s+ and you already know that the word after Mounted belongs to it.

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

3 Comments

No 'Mounted on' is just a string that contains the mount point on the system. Thanks though
@Tony check my edited answer. if the word mounted is the once causing problem. it should solve it
Thanks, the \s+ seems to have done the job.

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.