Extract sequence blocks


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract sequence blocks
# 1  
Old 03-25-2009
Extract sequence blocks

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
# 2  
Old 03-25-2009
"man fold"

Thanks
SHa
# 3  
Old 03-25-2009
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
# 4  
Old 03-25-2009
Quote:
Originally Posted by solli
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?
# 5  
Old 03-25-2009
Let's say my line is: 123456789123456789123456789

fold gives me:
123456789
123456789
123456789

but I need:
123456789
234567891
345678912
# 6  
Old 03-25-2009
ah, ok:
Code:
echo '123456789123456789123456789' | nawk -v len=9 '{l=length; for(i=1;i<=l-len+1; i++) print substr($0,i,len)}'


Last edited by vgersh99; 03-25-2009 at 01:03 PM..
# 7  
Old 03-25-2009
Thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract distinc sequence of letters

Hallo, I need to extract distinct sequence of letters for example from 136 to 193 Files are quite big, so I would prefer not to use "fold -w1" Thank you very much Input file look like this: 1 cttttacctt catgtgtttt tgcagatatt tgttcataat aacatcttct ttttaagtta 61 ttaaaatctt... (4 Replies)
Discussion started by: kamcamonty
4 Replies

2. Shell Programming and Scripting

Blocks of text in a file - extract when matches...

I sat down yesterday to write this script and have just realised that my methodology is broken........ In essense I have..... ----------------------------------------------------------------- (This line really is in the file) Service ID: 12345 ... (7 Replies)
Discussion started by: Bashingaway
7 Replies

3. Shell Programming and Scripting

Extract sequence from fasta file

Hi, I want to match the sequence id (sub-string of line starting with '>' and extract the information upto next '>' line ). Please help . input > fefrwefrwef X900 AGAGGGAATTGG AGGGGCCTGGAG GGTTCTCTTC > fefrwefrwef X932 AGAGGGAATTGG AGGAGGTGGAG GGTTCTCTTC > fefrwefrwef X937... (2 Replies)
Discussion started by: ritakadm
2 Replies

4. Shell Programming and Scripting

Extract sequences of bytes from binary for differents blocks

Hello to all, I would like to search sequences of bytes inside big binary file. The bin file contains blocks of information, each block begins is estructured as follow: 1- Each block begins with the hex 32 (1 byte) and ends with FF. After the FF of the last block, it follows 33. 2- Next... (59 Replies)
Discussion started by: Ophiuchus
59 Replies

5. Shell Programming and Scripting

Row blocks to column blocks

Hello, Searched for a while and found some "line-to-column" script. My case is similar but with multiple fields each row: S02 Length Per S02 7043 3.864 S02 54477 29.89 S02 104841 57.52 S03 Length Per S03 1150 0.835 S03 1321 0.96 S03 ... (9 Replies)
Discussion started by: yifangt
9 Replies

6. Shell Programming and Scripting

how to split this file into blocks and then send these blocks as input to the tool called Yices?

Hello, I have a file like this: FILE.TXT: (define argc :: int) (assert ( > argc 1)) (assert ( = argc 1)) <check> # (define c :: float) (assert ( > c 0)) (assert ( = c 0)) <check> # now, i want to separate each block('#' is the delimeter), make them separate files, and then send them as... (5 Replies)
Discussion started by: paramad
5 Replies

7. UNIX for Dummies Questions & Answers

Convert 512-blocks to 4k blocks

I'm Unix. I'm looking at "df" on Unix now and below is an example. It's lists the filesystems out in 512-blocks, I need this in 4k blocks. Is there a way to do this in Unix or do I manually convert and how? So for container 1 there is 7,340,032 in size in 512-blocks. What would the 4k block be... (2 Replies)
Discussion started by: rockycj
2 Replies

8. Shell Programming and Scripting

extract blocks of text from a file

Hi, This is part of a large text file I need to separate out. I'd like some help to build a shell script that will extract the text between sets of dashed lines, write that to a new file using the whole or part of the first text string as the new file name, then move on to the next one and... (7 Replies)
Discussion started by: cajunfries
7 Replies

9. Shell Programming and Scripting

Extract Pattern Sequence

Dear Collegues I have to extract Some pattern from raw text file using perl The input will be raw text. Pattern to get - Sequence of Capital Letter Words ( e.g. he is working in Center for Perl Studies. He will come tomorrow...) from thos I have to extract sequences like "Center for Perl... (5 Replies)
Discussion started by: jaganadh
5 Replies

10. Shell Programming and Scripting

How to extract a sequence of n lines from a file

Hi I want to be able to extract a sequence of n lines from a file. ideas, commands and suggestions would be highly appreciated. Thanks (4 Replies)
Discussion started by: 0ktalmagik
4 Replies
Login or Register to Ask a Question