0

I would like to get a single value from output.txt file, and run different other bash commands based on the returned value pattern;

cat output.txt enter code here

SAMPLE FILE DATA

{ "Topics": 
  [ 
    { "Name": "arn:aws:sns:us-west-2:123456789012:freezing-deploy-topic"}, 
    { "Name": "arn:aws:sns:us-west-2:123456789012:dense-deploy-topic" }, 
    { "Name": "arn:aws:sns:us-west-2:123456789012:tenki-deploy-topic" } 
  ] 
}

Shell script file

while read line
do 
    if [[ $line =~ 'tenki-deploy' ]]
    then 
        echo "$line"
    fi
done
Nic3500
  • 8,144
  • 10
  • 29
  • 40
itgeek
  • 549
  • 1
  • 15
  • 33
  • if you could use/install jq then jq is your tool here – snap Jul 30 '18 at 19:08
  • `jq -r '.Topics[].Name | select(test("tenki-deploy"))'` – Charles Duffy Jul 30 '18 at 20:00
  • BTW, `while read line` should pretty much always be `while IFS= read -r line`. Without the `IFS=`, you trim trailing whitespace; without the `-r`, you munge literal backslashes in the data, or (if such backslashes are just before EOL) can have a `read` continue onto the following line of input. – Charles Duffy Jul 30 '18 at 20:01
  • how to use exceptions eg. it should through an error when it could not find "tenki-deploy" from json file. and I want to use them in a if/while statement loop – itgeek Jul 31 '18 at 14:37

0 Answers0