Skip to main content
edited tags
Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 265
Source Link
FieryRider
  • 135
  • 1
  • 7

How to split string by string (multi-character) separator into an array?

Basically I'd like to split a string into an array by a string separator like sep. for example. Is there native bash way to do this without using tools like sed, awk, etc? I know I can split a string into an array by setting IFS and using read -ra but that doesn't work with string separators. And if there is not how you'd do it with tools like sed, awk, etc?

Let's say I have the string This is some sep.string and I'd like to split it into an array with 2 elements: This is some and string.