Use (( ))
for the numeric comparison:
if (( $(grep -c -- "LineString" "$file") >= 2 )); then
# your logic
fi
To loop through all files:
#!/bin/bash
shopt -s nullglob # make glob expand to nothing if there are no matching files
for file in *; do
[[ -f $file ]] || continue
if (( $(grep -c -- "LineString" "$file") >= 2 )); then
# your logic
fi
done
If you are dealing with very huge files and your grep
supports the -m
option, then you can use grep -cm 2
to optimize the reads:
#!/bin/bash
shopt -s nullglob
for file in *; do
[[ -f $file ]] || continue
if (( $(grep -cm 2 -- "LineString" "$file") >= 2 )); then
# your logic
fi
done