This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Using "grep" to count a string

I counted a string "Chr" in a .TXT file using grep -c "Chr" <file.txt>. However, got a number much smaller than the real number. Can anybody help me out with this? Thank you!

snp next-gen sequence

I think (not sure) grep give you the number of rows with "Chr" in it. So if you have two "Chr" in one row, it will count only as one.

Check spelling, try without the case-sensitive search, and see if there is a newline issue. Also, an example of your text file would be helpful to see what you are trying to match.

also try this.

grep -o chr file.vcf | wc -w

There is no spelling or case issue? What is the newline issue, please?

Hello,

Thank you very much for your reply. I checked spelling, tried case-sensitive search, and found only one "Chr" in one row. I tried all comands kindly provided here, but still could not get the right number. By the way, what is the newline issue?

What do you mean, the right number? grep doesn't make mistakes. It's going to find how many lines have "Chr" in them. What do you want it to do instead? Give an example of the data file please.

Hello chchl7!

This isn't a bioinformatics question so this post does not fit the main topic of this site. There are other sites that deal with questions like this, http://superuser.com springs to mind.

For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.

Also, please don't post additional comments as answers to your question, use the top level comments if responding to someone who has commented, rather than answered the question.

0 answers

No answers yet.

Log in to answer this question.