网络搜刮中的壳式算术。

问题描述 投票:0回答:1

所以,我这里有例子代码。

#!/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 结果的结果?

html bash curl calc expr
1个回答
2
投票

sed -n ' ...bash

$ num=$(xidel -se '//div[@class="mark_val"]/span[1]/text()' 'https://url')
$ num=$((${num//,/}+1)) # num was 14050
$ echo $num 

+

14051

xidel

$((...))

:Output

 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.orgBashFAQ002http:/mywiki.wooledge.orgCommandSubstitution。

奖金

你可以直接在 谢谢 雷诺 使用 语法 :

$ 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
'
© www.soinside.com 2019 - 2024. All rights reserved.