I’m trying to write a simple script that goes checks the number of lines that contain a certain string (which contains a double). However I’m having some issues. Here is the script I’ve written
#!/bin/bash
x=0.1
while [ $x -le 5 ]
do
cat b.txt | grep "Red: $x" | wc -l >> blah
x=$(( $x + 0.1 ))
done
However, when I try to execute it I get the following error which I’m not sure how to resolve:
/counter: line 4: [: 0.1: integer expression expected
Please could someone help me out?
Example file:
Red: 0.1
Red: 1.1
Red: 2.3
Red: 0.5
Red: 3.9
Red: 1.0
Red: 4.4
for floating-point operations, it’s best to use “bc”: here is a decent tutorial:
http://www.linuxjournal.com/content/floating-point-math-bash