-1

I have list extracted from a json output as below.

"Rel_70" "Rel_71" "Dev_795" "Dev_796" "Dev_797" "Devtest_10" "Devtest_12" 

Out of this, I want to extract values with Dev_* i.e I am interested to extract all values "Dev_795" "Dev_796" "Dev_797" .

1
  • The original JSON document that the values in the question are extracted from would be good to see. It would be easier to work with that than with a line of text with no structure. Commented Jul 11, 2021 at 7:14

3 Answers 3

0

To include all "Dev_[digits]" entries:

awk 'BEGIN {RS=" "} /Dev_[0-9]+/ {print}' inputfile 

Or, if you wanted specifically only to include those "Dev" entries:

awk 'BEGIN {RS=" "} /Dev_(795|796|797)/ {print}' inputfile 
0
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 
1
  • Can you put at least some prose around these answers so that the technically less competent have at least some chance of understanding what is going on here? Commented Jun 29, 2017 at 18:28
-1
awk 'ORS=" "{for(i=1;i<=NF;i++){if($i ~ /Dev_/){print $i}}}' filename 

output

"Dev_795" "Dev_796" "Dev_797" 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.