AishwaryaKulkarni AishwaryaKulkarni - 6 months ago 13
Bash Question

Get the string after a pattern in a matrix file and calculate it's length in bash

I have the following matrix file :

>ATCSTC ACD 3.44
0.39532879396435 0.105513888686126 0.105513888686126 0.393643427745405
0.00770456803068082 0.00770456803068082 0.00770456803068082 0.976886297348457
0.976886297348457 0.00770456803068082 0.00770456803068082 0.00770456803068082


There are many such files with extension .motif and I want to retrieve the string after ">" and calculate it's length. I tried using all the suggested solutions in here but could not get any solution.

Answer

awk to the rescue!

awk '/^>/{print length($1)-1}' file
6
Comments