将CURL结果传送到BC

时间:2019-04-09 17:28:01

标签: bash shell curl sed bc

我有一个CURL命令

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

假设上述命令输出一个字符串“ 我等了1天”。

如何将“我等了1天”转换为“我等了24小时”(即,将管道“ 1 * 24”传递给bc命令)?

谢谢。

1 个答案:

答案 0 :(得分:0)

我设法通过使用“ awk”命令解决了这个问题。例如,

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

请注意,-F'[:\ |]'是您需要的任何定界符的列表。

相关问题