Counting characters between ""

blackbone

Member
Joined
Mar 16, 2008
Messages
11
Reaction score
0
Hi guys,

I have a huge text file and I need to count the number of characters between qoutes ""...any idea how I can do this, say if I less the file and come to the part that I need to count?

:cool:
 
Depends really. What do you need the data for? Probably the most intuitive way would be to write a short program that would do it for you.

In C, you'd open the file, and use a char to loop through the entire file, progressing an index each time. Each time you encounter a quote, you toggle a flag that is checked for each loop and the program decides based on the flag whether or not to increment a variable. It all stops when you reach the end of the file.

In fact, this is pretty much what you'd do in ANY programming language.
 
copy and paste in word... do a word count / based on selection?
 
use a char to loop through the entire file, progressing an index each time. Each time you encounter a quote, you toggle a flag that is checked for each loop and the program decides based on the flag whether or not to increment a variable. It all stops when you reach the end of the file.


nah...

use some findchar command, and find the first instance of ".
run a inner loop, which goes character for character till it finds another " (also incrementing a counter variable every loop)
replace those characters with something else, go through the process again...ie: loop it
answer = counter variable.

yours would work, easilly, but mine would be faster as it skips all the garbage, only counting when it finds a " character. but speed won't matter for a program with such small scope..LOL
 
Basically I'm checking some logs...and if the number of characters between qoutes is too long, it normally results in a failure. I'm testing some software that sends messages and need to ascertain the maximum number of characters I can include - and these characters are contained in qoutes ""...
 
nah...

use some findchar command, and find the first instance of ".
run a inner loop, which goes character for character till it finds another " (also incrementing a counter variable every loop)
replace those characters with something else, go through the process again...ie: loop it
answer = counter variable.

yours would work, easilly, but mine would be faster as it skips all the garbage, only counting when it finds a " character. but speed won't matter for a program with such small scope..LOL

Show-off... In the same vein, one could just use an indexOf() function and then a .length() string method :p
 
grep -o '".*"' <filename> | wc -m

You can be more specific with the regex if you need to.
 
Top
Sign up to the MyBroadband newsletter
X