InputList="Item1,Item2,Item3,....,ItemN"
Desired output:
NewList1="Item1"
NewList2="Item2;Item3;....;ItemN"
Note that the separator of the original input list is a , (comma) whereas that of the new lists is a ; (semicolon).
Please suggest a suitable Bash script. Thanks.
CodePudding user response:
With bash
and its Parameter Expansion:
List1="Item1"
List2="Item2;Item3;....;ItemN"
List1="${InputArray%%,*}"
List2="${InputArray#*,}"
List2="${List2//,/;}"
echo "$List1"
echo "$List2"
Output:
Item1 Item2;Item3;....;ItemN