LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to check that my script can check if it has a specific range of charcters. (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-check-that-my-script-can-check-if-it-has-a-specific-range-of-charcters-835518/)

shirlcurl20 09-30-2010 10:04 PM

How to check that my script can check if it has a specific range of charcters.
 
Hi so I'm new to scripting and pretty much everything.
I made a script that counts the amount of times a word occurs in a specific file. but now i have to make the script check that the first argument (the word i'm looking to count) is made up of only the specific characters a,c,g,t. and i also have to make my script check that the second argument is a file that contains only a,c,g,t characters in it. if anyone could help that would be awesome!

Tinkster 09-30-2010 11:09 PM

Hi, welcome to LQ!


In cases such as this it's always best to provide some sample
data - I can't really make too much sense of your description.


Cheers,
Tink

rustek 11-16-2010 11:15 PM

Your obviously searching for DNA sequences.

You didn't say, so I'll assume your using bash.

To make sure the file only contains a,c,g, or t

egrep -xv [atcg]+ filename >/dev/null
RET=$?

$RET will be 1 if the file is clean, 0 if it is not.

To check your variable.

echo "$VAR" | egrep -xv [atcg]+ >/dev/null
RET=$?

$RET will be 1 if $VAR is clean, 0 if it is not.


All times are GMT -5. The time now is 12:41 AM.