Question: reduce size of string
0
gravatar for Jason
3 months ago by
Jason0
Jason0 wrote:

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

shell sequence python • 145 views
ADD COMMENTlink modified 3 months ago by cpad01128.3k • written 3 months ago by Jason0
3
gravatar for d-cameron
3 months ago by
d-cameron1.9k
Australia
d-cameron1.9k wrote:

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

ADD COMMENTlink modified 3 months ago • written 3 months ago by d-cameron1.9k
2
gravatar for cpad0112
3 months ago by
cpad01128.3k
India
cpad01128.3k wrote:

output:

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

input:

$ cat test.txt 
abcdtmrtnunzaeq
ygbwwqwtsazpklf
yuncspytaqwercl
ADD COMMENTlink written 3 months ago by cpad01128.3k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1599 users visited in the last hour