Skip to main content
added 203 characters in body
Source Link
AndreyS
  • 289
  • 3
  • 6
  • 15

I have a field version with value 2022.2.1. I need to get value 2022.2 in all my examples (string before and after the first delimiter).

version="2022.2.1"
echo "${version%.*}"
2022.2

This works. But if version contains multiple dots as delimiters (eg. version="2022.2.1.1") it will not work - I need here the value 2022.2

or even if version contains multiple versions in it it will not work (version="2022.12.1 2021.1.0"). Again in this example I need only the first value and it's first string before and after the first delimiter in total. So always I would like to get value 2022.2

What is the best practice for this use case? Thanks!

I have a field version with value 2022.2.1. I need to get value 2022.2 in all my examples (string before and after the first delimiter).

version="2022.2.1"
echo "${version%.*}"
2022.2

This works. But if version contains multiple dots as delimiters (eg. version="2022.2.1.1") it will not work or even if version contains multiple versions in it it will not work (version="2022.1.1 2021.1.0")

What is the best practice for this use case? Thanks!

I have a field version with value 2022.2.1. I need to get value 2022.2 in all my examples (string before and after the first delimiter).

version="2022.2.1"
echo "${version%.*}"
2022.2

This works. But if version contains multiple dots as delimiters (eg. version="2022.2.1.1") it will not work - I need here the value 2022.2

or even if version contains multiple versions in it it will not work (version="2022.2.1 2021.1.0"). Again in this example I need only the first value and it's first string before and after the first delimiter in total. So always I would like to get value 2022.2

What is the best practice for this use case? Thanks!

added 23 characters in body
Source Link
AndreyS
  • 289
  • 3
  • 6
  • 15

I have a field version with value 2022.2.1. I need to get value 2022.22022.2 in all my examples (string before and after the first delimiter).

version="2022.2.1"
echo "${version%.*}"
2022.2

This works. But if version contains multiple dots as delimiters (eg. version="2022.2.1.1") it will not work or even if version contains multiple versions in it it will not work (version="2022.1.1 2021.1.0")

What is the best practice for this use case? Thanks!

I have a field version with value 2022.2.1. I need to get value 2022.2 (string before and after the first delimiter).

version="2022.2.1"
echo "${version%.*}"
2022.2

This works. But if version contains multiple dots as delimiters (eg. version="2022.2.1.1") it will not work or even if version contains multiple versions in it it will not work (version="2022.1.1 2021.1.0")

What is the best practice for this use case? Thanks!

I have a field version with value 2022.2.1. I need to get value 2022.2 in all my examples (string before and after the first delimiter).

version="2022.2.1"
echo "${version%.*}"
2022.2

This works. But if version contains multiple dots as delimiters (eg. version="2022.2.1.1") it will not work or even if version contains multiple versions in it it will not work (version="2022.1.1 2021.1.0")

What is the best practice for this use case? Thanks!

Source Link
AndreyS
  • 289
  • 3
  • 6
  • 15

bash - take string before and after the first delimiter

I have a field version with value 2022.2.1. I need to get value 2022.2 (string before and after the first delimiter).

version="2022.2.1"
echo "${version%.*}"
2022.2

This works. But if version contains multiple dots as delimiters (eg. version="2022.2.1.1") it will not work or even if version contains multiple versions in it it will not work (version="2022.1.1 2021.1.0")

What is the best practice for this use case? Thanks!