Need help comparing output of grep -c to a value using -gt and -lt in bash
Hi all,
I have a folder of .fa files. I want to get rid of files that have more than 50 or fewer than four occurrences of the greater-than symbnol (">"). Here is the code I've come up with so far but I don't think the output of grep -c is being read as a number. I feel like bc needs to come into play somehow but I can't figure out how to make bash see this variable as a number. Any help would be greatly appreciated! Code:
mkdir more_than_50_seqs Kevin |
Quote:
Are you checking the count of duplicate .fa files or counting all .fa files ? in both cases i dont see grep -c or the code you wrote is much of a use here rather using wc -l while listing files can give you count of occurences of the file. better see man page first. here is what you can do once you decide what you want to count: get the count , compare it and check if teh dir you want exists if not make one else move the file to a dir depending on the count. |
I see a few issues:
1. No space either side of [ and ], remember that [ is a command, so you would not write lsdir, you would write ls dir 2. elseif is incorrect in bash, you want to use elif 3. If you use (()) instead of [] you can perform arithmetic comparisons with familiar symbols Code:
if (( NUMBER_OF_OGs > 50 )) Code:
NUMBER_OF_OGs=$(grep -c '\>' $FILENAME) 6. $() is clearer than `` and can be nested easily 7. Based on your description, I am not 100% sure you are performing the correct test?? You say you want files with greater than 50 occurrences of '>', however the -c option for grep will return the number of lines that match your criteria and not the number of '>' that appear, ie. you could have a file with one line and 51 '>' but this would not return as the -c will return only 1 |
Thanks guys!
Grail, thanks for noticing that I'm only counting lines with a greater than symbol but FYI the file format that I'm using will always have one or zero greater than symbols per line. This code with your suggestions did the trick: Code:
mkdir more_than_50_seqs Kev |
Code:
#!/bin/bash |
You shouldn't use upper case variable names.
http://wiki.bash-hackers.org/scripti...variable_names http://wiki.bash-hackers.org/scripting/style |
All times are GMT -5. The time now is 03:33 AM. |