I am working on a shell script to move files if certain percentage of the lines contain a certain string.
I've got ~2000 files in a directory that each contain a single column of data. The number of rows in each file varies. The first row is a header, and the other rows contain numbers larger than 0, to 6 decimal places. Ex:
OMEGA 0.000010 0.000010 0.042214 0.042214 0.042214 0.042214 1.147412
I am interested in all files where at least 10% of the rows contain a value larger than 1. I am using the ratio of lines containing "1." to "." -- but I am struggling with syntax. ".omega" is the extension for the files I am interested in.
Here is what I have:
for file in *.omega do if [ $(($(grep '1.' $file | wc -l) / $(grep '.' $file | wc -l)) * 100) -ge 10 ]; then mv $file positive_COGs/ fi done
I have played around with parenthesis/bracket placement, and have been unsuccessful. Additionally -- I am not sure if it is appropriate to use "-ge" to compare the % (not an integer) to the integer of "10" (?).
Any suggestions are much appreciated. I am using bash to execute the script.