0

I have a bash script that gives me the following output:

'string1': {'something': u'2.000', 'anotherthing': u'3.0000000'
'string2': {'something': u'1.000', 'anotherthing': u'1.85695664'
'string3': {'something': u'1.000', 'anotherthing': u'4.0000000'
'string4': {'something': '01.000', 'anotherthing': u'0.43448059'

I want to assign each line with a variable ( strinx) ....I`ve tried awk '{print "var"NR"="$0}' , but it just creates a variable like this:

var1=string1': {'something': u'2.000', 'anotherthing': u'3.0000000'
var2='string2': {'something': u'1.000', 'anotherthing': u'1.85695664'
var3='string3': {'something': u'1.000', 'anotherthing': u'4.0000000'
var4='string4': {'something': '01.000', 'anotherthing': u'0.43448059'.

How can i get more than 1 variables? Thank you

George Vasiliou
  • 6,130
  • 2
  • 20
  • 27
lolren
  • 29
  • 1
  • 1
    use the right tool for the job.. https://github.com/stedolan/jq – MostWanted Jun 10 '18 at 22:52
  • Don't parse json with sed/awk use [jq](https://stackoverflow.com/tags/jq/info). – Cyrus Jun 11 '18 at 01:00
  • 1
    The [XY](http://meta.stackexchange.com/a/66378) problem is asking about your attempted solution rather than your actual problem. – Cyrus Jun 11 '18 at 01:01
  • Possible duplicate of [Creating an array from a text file in Bash](https://stackoverflow.com/questions/30988586/creating-an-array-from-a-text-file-in-bash) – kvantour Jun 11 '18 at 09:35
  • Also https://stackoverflow.com/questions/11393817/read-lines-from-a-file-into-a-bash-array – kvantour Jun 11 '18 at 09:36
  • What you are interested in is refered to as an `array`. You might want to store each line of your text file in an array (lets call it `var`) and then you can refere to each element as `var[1]`, `var[2]`, ... . The duplicates indicate how you can do this. – kvantour Jun 11 '18 at 09:38

0 Answers0