-2

I have a CURL command

echo "{cur_format}" | curl -w @- -s -o /dev/null https://example.com

Let's say the above command outputs a string of "I waited 1 day".

How can I convert "I waited 1 day" to "I waited 24 hours" (i.e. pipe "1 * 24" to the bc command")?

Thank you.

gye
  • 1,374
  • 3
  • 16
  • 27
  • You would have to extract the 1, multiply, and then shove it back into the string – that other guy Apr 09 '19 at 17:49
  • A better solution might be to pipe to Awk, but. what exactly the script should look like depends on how general you need it to be. `awk '{$3 *= 24; $4 = "hours"; print }'` does what you ask. – tripleee Apr 09 '19 at 18:09
  • @tripleee Thank you! "awk" solves my problem. – gye Apr 09 '19 at 18:51
  • Your question should remain strictly a question. Feel free to post your latest edit as an answer instead. – tripleee Apr 09 '19 at 18:51

1 Answers1

0

I managed to resolve this by using "awk" command. For example,

echo "{cur_format}" | curl -w @- -s -o /dev/null https://example.com | awk -F'[:\|]' '{print $1 ":" (($2*24)) "|" $3 "|" $4;}'

Note that -F'[:\|]' is a list of any delimiters you need.

gye
  • 1,374
  • 3
  • 16
  • 27