This is a test version of Biostars. For the public version, visit https://www.biostars.org.
reduce size of string

Hello all

I have txt file of 400 sequences.

abcdtmrtnunzaeq

ygbwwqwtsazpklf

yuncspytaqwercl

How can I write shell command to delete the first three letter and also delete the end of the three letter at each row and save that in new txt file

Result should be save in new txt file like this:

dtmrtnunz

wwqwtsazp

cspytaqwe

sequence shell python

2 answers

cut -b 4- input.txt | rev | cut -b 4- | rev > output.txt

This removes the first 3 characters (by output the 4th character onward) of input.txt, reverses each line, removes the first 3 characters of the reversed line (which are the last 4 characters of the non-reversed line), reverses each line back to normal, then outputs to a output.txt

Edit: if all your lines are 16 characters long then you can just do cut -b 4-12 input.txt > output.txt

output:

$ while read line;do echo  ${line:3:-3};done < test.txt 
dtmrtnunz
wwqwtsazp
cspytaqwe

input:

$ cat test.txt 
abcdtmrtnunzaeq
ygbwwqwtsazpklf
yuncspytaqwercl

Log in to answer this question.