我从 json 输出中提取了列表,如下所示。
"Rel_70" "Rel_71" "Dev_795" "Dev_796" "Dev_797" "Devtest_10" "Devtest_12"
由此,我想用 Dev_* 提取值,即我有兴趣提取所有值 "Dev_795" "Dev_796" "Dev_797" 。
答案1
要包含所有“Dev_[digits]”条目:
awk 'BEGIN {RS=" "} /Dev_[0-9]+/ {print}' inputfile
或者,如果您只想专门包含那些“Dev”条目:
awk 'BEGIN {RS=" "} /Dev_(795|796|797)/ {print}' inputfile
答案2
tr ' ' '\n' < jsonfile | grep '"Dev_'
perl -lne 'print for /"Dev_\d+"/g' jsonfile
while read -ra A; do for a in "${A[@]}"; do case $a in '"Dev_'* ) echo "$a" ;; esac; done; done < jsonfile
答案3
awk 'ORS=" "{for(i=1;i<=NF;i++){if($i ~ /Dev_/){print $i}}}' filename
输出
"Dev_795" "Dev_796" "Dev_797"