0

I have a text file of dictionaries, these dictionaries are not separated by commas, is it possible to separate them and get nice elements in a list, with each element representing a dictionary.

E.g. : what I have: {} {} {}

What I want [{}, {}, {}]

Can someone please suggest the best way to do it.

Thanks

Inder
  • 3,711
  • 9
  • 27
  • 42

2 Answers2

1

This is easily done with sed(1). Assuming filename.txt is the name of file with dictionaries, the invocation is

sed -i 's/^/[/ ; s/$/]/ ; s/} {/}, {/g' filename.txt
bipll
  • 11,747
  • 1
  • 18
  • 32
1

I am new to coding but I think instead of trying to convert a text to dictionaries, you can just change the data-structure to an associative array.

Not sure if it will help you but this is something that helped me under similar circumstances.

dictionaries style database in shell

Inder
  • 3,711
  • 9
  • 27
  • 42
  • Thanks but this is not what I wished to do, It was an automatic feed, sadly I can't change the data structure. – Inder Jul 04 '18 at 10:51