Reputation: 4148
I have created a shell script below that checks whether the file out.txt contains any line with the text "Billing_20160210". I am getting the error in the regular expression part which states that "[[: not found". Not sure whether i am missing something. Any help would be appreciated.
#!/bin/bash
bq ls test:Dataset_test > out.txt
cat out.txt | while read LINE
do
if [ LINE = *"Billing_20160210"* ];
then
echo "Processing $LINE"
fi
done
Edit not working:
#!/bin/bash
bq ls geotab-bigdata-test:JS_test > out.txt
cat out.txt | while read LINE
do
if [[ $LINE == *"DailyBillingTest_20160210"* ]];
then
echo "Processing $LINE"
fi
done
Upvotes: 0
Views: 83
Reputation: 157992
Don't use a shell loop to filter a file line by line. Use grep
as a filter here:
grep 'Billing_20160210' out.txt | while read -r line ; do
echo "processing ${line}"
done
Or even without a temporary file:
bq ls test:Dataset_test | grep 'Billing_20160210' | while read -r line ; do
echo "processing ${line}"
done
Upvotes: 1