Reputation: 115
req=`bxp report change-summary $startDate $startDate -iad -y | grep -A2 "Request ID"
The above script gives the below output
Request ID ------------ 10481066
I want to cut only the number 10481066
, I tried with number grep
and other cut
which is not working. Can anyone suggest?
Upvotes: 0
Views: 393
Reputation: 1
I would do manipulating the final string,
req="Request ID ------------ 10481066"
result=${req%-*}
Upvotes: 0
Reputation: 115
i just did this way
req=bxp report change-summary $startDate $startDate -iad -y | grep -A2 "Request ID" | grep -E "^[0-9]"
any way thanks for your help
Upvotes: 0
Reputation: 6335
Just some alternatives to 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"
All above return 10481066
PS: Cut default delimiter is tab, you need to declare with -d
option space as delimiter in order cut to work with your data.
Upvotes: 0
Reputation: 785098
Assuming your output Request ID ------------ 10481066
is all in a single line, you can just replace grep
with this awk
command:
req=$(bxp report change-summary $startDate $startDate -iad -y|awk '/Request ID/{print $NF}')
Upvotes: 1