0

The Linux command is sudo parted /dev/sda unit s print free | tail -2. In my case it returns something like this:

        34605056s  67108830s  32503775s  Free Space

I need to capture the first number string and the second number string.

The goal is to create a new partition fitting the remaining free space perfectly.

I tried to use grep, but the best I could achieve was just getting colored matched numbers, but they can't be used in script as parameters:

sudo parted /dev/sda unit s print free | tail -2 | grep -oP '(\d+s\b)'

gives

34605056s
67108830s
32503775s

I need something that would return exactly '34605056s' and '67108830s' that I would be able to put into mkpart command.

2 Answers 2

2

Would you please try:

read -r start end _ < <(sudo parted /dev/sda unit s print free | tail -2)

then you can pass the variables $start and $end to mkpart

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

Comments

2

AWK comes in handy:

echo "        34605056s  67108830s  32503775s  Free Space" |
  awk '{print $1, $2}'

Output:

34605056s 67108830s

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.