Я выполняю следующую команду:
aws ec2 describe-instances --filters "Name=ip-address,Values=MY_IP" | grep InstanceId
и я добираюсь:
"InstanceId": "i-b0f13081",
Как может я только получать следующее:
i-b0f13081
Это - то, что я попробовал:
aws ec2 describe-instances --filters "Name=ip-address,Values=MY_IP" | grep InstanceId | gawk -F: '{ print $2 }'
"i-b0f13081",
awk
:
Набор "
как разделитель полей, и получают 4-е поле:
% awk -F'"' '{print $4}' <<<'"InstanceId": "i-b0f13081",'
i-b0f13081
<час> Так же cut
:
% cut -d'"' -f4 <<<'"InstanceId": "i-b0f13081",'
i-b0f13081
<час> grep
с PCRE (-P
):
% grep -Po ':\s*"\K[^"]+' <<<'"InstanceId": "i-b0f13081",'
i-b0f13081
<час> расширение параметра Shell:
% var='"InstanceId": "i-b0f13081",'
% var="${var%\"*}"
% echo "${var##*\"}"
i-b0f13081
<час> sed
:
% sed -E 's/^[^:]+:[^"]+"([^"]+).*/\1/' <<<'"InstanceId": "i-b0f13081",'
i-b0f13081
<час> perl
:
% perl -pe 's/^[^:]+:[^"]+"([^"]+).*/$1/' <<<'"InstanceId": "i-b0f13081",'
i-b0f13081
<час> python
:
% python -c 'import sys; print sys.stdin.read().split("\"")[3]' <<<'"InstanceId": "i-b0f13081",'
i-b0f13081