0

I have a bash script

counter=0
for file in /home/ec2-user/Workspace/events_parts/*
do
        counter=$[counter + 1]
        event=$(cat $file | jq '.Event')
        echo $event
        if [ "$event" = "Time Exceeded" ]  || [ "$event" = "Load Time" ]; then
                echo "Coming Here"
                jq ".url = \"$(jq '.Message' $file | sed 's/.*proxy=\([^&]*\).*/\1/')\"" $file 
        else
                jq ".url = null"
        fi
done
~   

In the bash script above I am trying to extract Event field from a JSON file and check for two possible values.if [ "$event" = "Time Exceeded" ] || [ "$event" = "Load Time" ]; is not workign as I would expect. I have verified that the values that I am comparing against are indeed there.

1
  • 1
    @Cyrus - ok, reopened - but the OP should add more descriptive headlines. Commented Mar 18, 2015 at 1:25

1 Answer 1

2

Check once if there are leading or trailing unwanted characters (whitespace, newline ...) in output of cat $file | jq '.Event':

cat $file | jq '.Event' | hexdump -C

Update:

Replace

[ "$event" = "Time Exceeded" ]

by

[ "$event" = "Time Exceeded." ]

or replace by

[ "${event%.}" = "Time Exceeded" ]

or replace by

[[ "$event" =~ "Time Exceeded" ]]

to match a substring. ${event%.} crops a trailing ..

Sign up to request clarification or add additional context in comments.

1 Comment

"Time Exceeded". There is a "." at the end.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.