-1

I get the data with wget.

Example of the output:

[{"id":15654014,"price":6.3e-06,"amount":1.7,"total":1.071e-05,"market":"somebtc","created_at":1622541615,"taker_type":"buy"}]

The goal is to get the price value which is the 6.3e-06, so the pattern is "price":, but the next pattern is to get everything until we reach , so we can be sure that we take only the price

My solution:

cat price.txt | cut -c25- | sed 's/.//9g' > pricefin.txt

So I basically remove the first 25 charachters and then remove everything except the first 9.

However the value of 6.3e-06 can be sometimes less or more than just 9.

What can be the solution in my case?

Cyrus
  • 84,225
  • 14
  • 89
  • 153
blockxyz
  • 13
  • 4

1 Answers1

0

This will do it:

sed 's/.*"price":\(.*\),"amount.*/\1/' your_file > new_file

The ways it's working is as follows:

  • I remember the stuff in between the above using \( and \)
  • In this case its the stuff coming after "price": but before ,"amount
  • Then replace with the remembered content \1
  • and put it into a new file
mattb
  • 2,787
  • 2
  • 6
  • 20