req=`bxp report change-summary $startDate $startDate -iad -y | grep -A2 "Request ID"
上述脚本给出以下输出壳牌切grep命令
Request ID ------------ 10481066
我希望削减仅数10481066
,我试图与数grep
等cut
这是行不通的。任何人都可以建议
req=`bxp report change-summary $startDate $startDate -iad -y | grep -A2 "Request ID"
上述脚本给出以下输出壳牌切grep命令
Request ID ------------ 10481066
我希望削减仅数10481066
,我试图与数grep
等cut
这是行不通的。任何人都可以建议
只是一些替代AWK:
$ egrep -o '[0-9]+' <<<"This is a line with Request ID ------------ 10481066"
$ cut -d' ' -f4 <<<"Request ID ------------ 10481066"
$ egrep -o '[0-9]+$' <<<"This is a line with number 35546 with Request ID ------------ 10481066"
上述所有收益10481066
PS:剪切默认分隔符是标签,你需要用声明选项空间作为分隔符以便与您的数据一起使用。
假设你的输出Request ID ------------ 10481066
是在一个单一的线,你可以用这个awk
命令替换grep
:
req=$(bxp report change-summary $startDate $startDate -iad -y|awk '/Request ID/{print $NF}')
我只是做了这样
REQ = bxp report change-summary $startDate $startDate -iad -y | grep -A2 "Request ID" | grep -E "^[0-9]"
任何方式感谢您的帮助
这是一种低效的方法,因为它涉及2个附加命令。 – anubhava
我会做操纵最终的字符串,
req="Request ID ------------ 10481066"
result=${req%-*}
是'请求ID - ---------- 10481066'全部在单行? – anubhava
该数字是该行中的第四个*空格*分隔字段。使用[cut]命令应该非常容易(http://man7.org/linux/man-pages/man1/cut.1.html)。 –