-2

I am reading a file which contains the following config as an array:

$ cat ./FILENAME
*.one.dev.arr.name.com
*.one.dev.brr.name.com
*.one.dev.sic.name.com
*.one.dev.sid.name.com
*.one.dev.xyz.name.com
*.one.dev.yza.name.com

The array is read IFS='$\n' read -d '' -r -a FILENAME < ./FILENAME

I need the format to be of the following format:

'{*.one.dev.arr.name.com,*.one.dev.brr.name.com,*.one.dev.sic.name.com,*.one.dev.sid.name.com,*.one.dev.xyz.name.com,*.one.dev.yza.name.com}'

I've tried using printf, the tricky part is the wildcard(*) at the start of the name.

markp-fuso
  • 16,615
  • 3
  • 11
  • 27
mac
  • 1,139
  • 3
  • 9
  • 18
  • Do you _need_ an array? Why use an array at all, just https://stackoverflow.com/questions/2764051/how-to-join-multiple-lines-of-file-names-into-one-with-custom-delimiter – KamilCuk Oct 11 '21 at 08:33
  • please update the question with the `printf` command(s) you've tried and the (wrong) output generated by said command(s) – markp-fuso Oct 11 '21 at 19:01
  • I don't think the `IFS/read` command is populating the `FILENAME[]` array properly; run `typeset -p FILENAME` to see the contents of the array; consider using `mapfile -t FILENAME < FILENAME` for loading the `FILENAME[]` array; might also want to rethink the name of the file and/or the array, as is the use of `FILENAME` for both could be a bit confusing for someone else having to maintain this script – markp-fuso Oct 11 '21 at 19:05

1 Answers1

1

Just output what you want to output - { and } and join lines with ,:

echo "{$(paste -sd, FILENAME)}"

If you want with an array, you can just:

echo "{$(IFS=, ; echo "${array[*]}")}"
KamilCuk
  • 96,430
  • 6
  • 33
  • 74