Note that there are some explanatory texts on larger screens.

plurals
  1. POSplit string into array in bash
    primarykey
    data
    text
    <p>I am looking for a way to split a string in bash over a delimiter string, and place the parts in an array.</p> <p>Simple case:</p> <pre><code>#!/bin/bash b="aaaaa/bbbbb/ddd/ffffff" echo "simple string: $b" IFS='/' b_split=($b) echo ; echo "split" for i in ${b_split[@]} do echo "------ new part ------" echo "$i" done </code></pre> <p>Gives output </p> <pre><code>simple string: aaaaa/bbbbb/ddd/ffffff split ------ new part ------ aaaaa ------ new part ------ bbbbb ------ new part ------ ddd ------ new part ------ ffffff </code></pre> <p>More complex case:</p> <pre><code>#!/bin/bash c=$(echo "AA=A"; echo "B=BB"; echo "======="; echo "C==CC"; echo "DD=D"; echo "======="; echo "EEE"; echo "FF";) echo "more complex string" echo "$c"; echo ; echo "split"; IFS='=======' c_split=($c) ;# &lt;---- LINE TO BE CHANGED for i in ${c_split[@]} do echo "------ new part ------" echo "$i" done </code></pre> <p>Gives output:</p> <pre><code>more complex string AA=A B=BB ======= C==CC DD=D ======= EEE FF split ------ new part ------ AA ------ new part ------ A B ------ new part ------ BB ------ new part ------ ------ new part ------ ------ new part ------ ------ new part ------ ------ new part ------ ------ new part ------ ------ new part ------ C ------ new part ------ ------ new part ------ CC DD ------ new part ------ D ------ new part ------ ------ new part ------ ------ new part ------ ------ new part ------ ------ new part ------ ------ new part ------ ------ new part ------ EEE FF </code></pre> <p>I would like the second output to be like </p> <pre><code>------ new part ------ AA=A B=BB ------ new part ------ C==CC DD=D ------ new part ------ EEE FF </code></pre> <p>I.e. to <strong>split</strong> the string on a <strong>sequence of characters</strong>, instead of one. How can I do this?</p> <p>I am looking for an answer that would only modify this line in the second script:</p> <pre><code>IFS='=======' c_split=($c) ;# &lt;---- LINE TO BE CHANGED </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload