Artificial intelligent assistant

Count characters in line after first grep result, but removing new line from count **The problem:** I have multiple text files (.fas), which look like this: file1.fas: >species1 AICGICVIAGIAIYIAAICG >species2 AICGIVVYICAGAYICAGCG file2.fas: >species1 AIG >species2 GCI I'm interested in counting the number of characters in the second line (it's the same across all the species in one file as they are aligned. **My current one liner:** for i in *.fas; do echo -n "$i," && grep -m 1 -A 1 '>' $i | tail -n 1 | wc -c; done; This works to an extent but is counting one number higher than the actual number of characters, as it is counting the newline character. How do I fix this so it only counts the number of characters excluding newline characters? **Current output:** file1.fas,21 file2.fas,4 **Desired output:** file1.fas,20 file2.fas,3

* `| wc -l` prints the number of lines.
* `| wc -c` prints the number of chars, including newline.
* `| wc -lc` prints both (number of lines first).



So you can simply subtract them: (write it instead of `|wc -c`)


| wc -lc | awk '{print $2 - $1}'


If you only print your sequence on one line, you can substract 1 instead of the number of newlines.

Or you can use `awk` only, match the whole line and count its chars:


| awk '{match("[A-Z]*");print RLENGTH}'


`RLENGTH` is the length of the match (here, it's the whole line). Here, I assume you use only capital letters, else, use `.` instead of `[A-Z]`.

On `vim` (text editor, so it could be incompatible with your script), visually select your area (one line or more) and run:


:'<,'>s/[A-Z]*//gn


You can also delete the newline characters with `tr` (also works for several lines) :


| tr -d '\
' | wc -c


Btw, there is probably lots of other ways to do it.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy d701772466e6166efe65a22f4ef302ee