次の形式の文字列があります
id;some text here with possible ; inside
の最初の発生でこれを2つの文字列に分割しようとしています;
。したがって、次のようにid
する必要があります。some text here with possible ; inside
文字列を分割する方法(使用)を知っていますが、左側の部分cut -d ';' -f1
にあるため、より多くの部分に分割されます。;
ベストアンサー1
cut
適切なツールのようです。
bash-4.2$ s='id;some text here with possible ; inside'
bash-4.2$ id="$( cut -d ';' -f 1 <<< "$s" )"; echo "$id"
id
bash-4.2$ string="$( cut -d ';' -f 2- <<< "$s" )"; echo "$string"
some text here with possible ; inside
しかし、read
より適切なものは次のとおりです。
bash-4.2$ IFS=';' read -r id string <<< "$s"
bash-4.2$ echo "$id"
id
bash-4.2$ echo "$string"
some text here with possible ; inside