-2

How to split

"DB-ConnString","Server=tcp:database.windows.net,1433;Initial Catalog=db;Persist Security Info=False;User ID=DATAFACTORY;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;Authentication='Identity';"

to an array?

IFS="," read -r -a my_array <<< "$line" doesn't seem to do the trick.

Socowi
  • 25,550
  • 3
  • 32
  • 54
JhnWorks
  • 3
  • 3
  • 3
    it looks like you want split the string based on a comma but you appear to have a comma as part of the data in the `"Server..."` portion; how many elements are you expecting in the array? 2 or 3? do you also want to split on `;`? it would help if you update the question with what you expect the array contents to look like – markp-fuso Aug 04 '21 at 18:50
  • Strings can be split in thousands of ways. You need to explain how you want it split. – svin83 Aug 04 '21 at 19:26
  • comma is the delimiter. key being "DB-ConnString", value is the rest of it - "Server=tcp:database.windows.net,1433;Initial Catalog=db;Persist Security Info=False;User ID=DATAFACTORY;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;Authentication='Identity';" – JhnWorks Aug 04 '21 at 20:51
  • I'd suggest using perl or python or another language with a real CSV parser available. – Shawn Aug 04 '21 at 22:42

1 Answers1

0

Reset your delimiter to something not embedded in your data.

$: echo "$line"
"DB-ConnString","Server=tcp:database.windows.net,1433;Initial Catalog=db;Persist Security Info=False;User ID=DATAFACTORY;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;Authentication='Identity';"

$: IFS="|" read -r -a my_array <<< "${line//\",\"/\"\|\"}" # change "," to "|"
$: printf "[%s]\n" "${my_array[@]}"                        # show the results
["DB-ConnString"]
["Server=tcp:database.windows.net,1433;Initial Catalog=db;Persist Security Info=False;User ID=DATAFACTORY;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;Authentication='Identity';"]
Paul Hodges
  • 13,382
  • 1
  • 17
  • 36