0

For a job, I need to retrieve values in a file extracted with curl -o in a .txt file

I explain, for the moment, I managed to extract from the JSON, the necessary information via cut. My problem is that I can't display it correctly: 6:12:46 AM 5:20:41 PM Sunrise is expected at and sunset at .

I would like in this format : Sunrise is expected at 6:12:46 AM and sunset at 5:20:41 PM

How to do it please ? For the moment here is my bash code :

#!/bin/bash
curl -o test.txt https://api.sunrise-sunset.org/json?lat=48.813875&lng=2.392521
SUNSET= cut -c 24-33 test.txt
SUNRISE= cut -c 46-55 test.txt
echo "Sunrise is expected at" $SUNRISE "and sunset at $SUNSET."

Thanks

Gautier
  • 1
  • 1
  • Don't use `cut` to process JSON, use a tool like `jq`. Hard-coding specific indexes is just wrong. – Barmar Oct 11 '22 at 19:49
  • 1
    Previous advice notwithstanding, I think the problem you're having is that you generally want to use a subshell in the form `$()` to store the result in a variable. e.g. `SUNRISE=$(cut -c 46-55 test.txt)`. – EdmCoff Oct 11 '22 at 19:53

0 Answers0