awk
:
Defina "
como delimitador de campo e obtenha o quarto campo:
% awk -F'"' '{print }' <<<'"InstanceId": "i-b0f13081",'
i-b0f13081
Similarmente cut
:
% cut -d'"' -f4 <<<'"InstanceId": "i-b0f13081",'
i-b0f13081
grep
com PCRE ( -P
):
% grep -Po ':\s*"\K[^"]+' <<<'"InstanceId": "i-b0f13081",'
i-b0f13081
Expansão do parâmetro shell:
% var='"InstanceId": "i-b0f13081",'
% var="${var%\"*}"
% echo "${var##*\"}"
i-b0f13081
sed
:
% sed -E 's/^[^:]+:[^"]+"([^"]+).*//' <<<'"InstanceId": "i-b0f13081",'
i-b0f13081
perl
:
% perl -pe 's/^[^:]+:[^"]+"([^"]+).*//' <<<'"InstanceId": "i-b0f13081",'
i-b0f13081
python
:
% python -c 'import sys; print sys.stdin.read().split("\"")[3]' <<<'"InstanceId": "i-b0f13081",'
i-b0f13081