Extract text between two character positions

Greetings.

I need to extract text between two character positions, e.g: all text between character 4921 and 6534.

The text blocks are FASTA-format sequence of whole chromosomes, so basically a million A, T, G, C, combinations. E.g:

>Chr_1
ACCTGTTCAACTCTCAGGACTCTCAGGTCAACTCTCAG
CAACTCTCAGGAACTCTCAGGTCAACTCTCACTCTCAG
GTCAACTCTCCAGGAACTCTCCACTCTCAGAGGTCAAC
.......

I need to extract a region of genes, I know the character positions that are the boundaries.

I need the equivalent of what this does for lines:

sed -n 'line1,line2p" > new_file.txt

But for character positions.

Thanks!

See if this works:

awk 'NR>1{p=$0;sub($1 ORS,x,p);sub(ORS,x,p); print RS $1 ORS substr(p, 4921,6534-4921+1)}' RS=\> OFS= infile
1 Like

Perfect! Het werkt! Bedankt!

Nothing to thank :wink: