solli
1
Hi,
I have an one-line file consisting of a sequence of 660 letters. I would like to extract 9-letter blocks iteratively:
ASDFGHJKLQWERTYUIOPZXCVBNM
first block: ASDFGHJKL
1nd block: SDFGHJKLQ
What I have so far only gives me the first block, can anyone please explain why?
cat file | awk '{pep=""; for (i=0; i<=NF; i++); (pep=substr($0,i,9)); {print pep}}'
Cheers,
S
solli
3
Well the problem with "fold" is it (as the name hints) only folds my sequence and gives me 9-letter long blocks.
What I need is to go through the line, letter by letter, and extract 9-letter long blocks...
But thanks anyway, fold with surely be useful to me in the future!
/S
how's that different from what 'fold' provides?
solli
5
Let's say my line is: 123456789123456789123456789
fold gives me:
123456789
123456789
123456789
but I need:
123456789
234567891
345678912
ah, ok:
echo '123456789123456789123456789' | nawk -v len=9 '{l=length; for(i=1;i<=l-len+1; i++) print substr($0,i,len)}'
perl
$str="ASDFGHJKLQWERTYUIOPZXCVBNM";
$tmp=reverse $str;
$tmp=~s/(?=(.{6})+$)/_/g;
$tmp=reverse $tmp;
print $tmp;