所以,我这里有例子代码。
#!/bin/bash
clear
curl -s https://www.cnbcindonesia.com/market-data/currencies/IDR=/USD-IDR |
html2text |
sed -n '/USD\/IDR/,$p' |
sed -n '/Last updated/q;p' |
tail -n-1 |
head -c+6 && printf "\n"
exit 0
这应该可以打印出14000到15000的数字范围。
让我们从最基本的开始,我必须要做的是为了打印 result + 1
因此,如果打印输出是14000,并将其递增为1,就会变成14001。我想 html2text 的结果是无法计算的,因为它应该是字符串输出而不是整数。
我更想知道的是,如何计算两个 curl 结果的结果?
sed -n ' 导致命令 "cmd "与参数 "foo bar "一起执行,"$(...) "将被替换为"..."。...What I would do, bash
$ num=$(xidel -se '//div[@class="mark_val"]/span[1]/text()' 'https://url')
$ num=$((${num//,/}+1)) # num was 14050
$ echo $num
14051
$((...))
Explanations"$(cmd "foo bar")"
is an arithmetic substitution. After doing the arithmetic, the whole thing is replaced by the value of the expression. See http:. 见 http:/mywiki.wooledge.orgBashFAQ002 和 http:/mywiki.wooledge.orgCommandSubstitution。
你可以直接在 xidel谢谢 雷诺 使用 xquery 语法 :
$ xidel -s <url> e 'replace(//div[@class="mark_val"]/span[1],",","") + 1'
并做2个值的加法运算。
$ xidel -s <url> -e '
let $num:=replace(//div[@class="mark_val"]/span[1],",","")
return $num + $num
'