Reputation: 15010
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.
Upvotes: 0
Views: 875
Reputation: 88889
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 .
.
Upvotes: 2