Question: reduce size of string
0
gravatar for Jason
10 days 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 • 83 views
ADD COMMENTlink modified 10 days ago by cpad01125.3k • written 10 days ago by Jason0
3
gravatar for d-cameron
10 days ago by
d-cameron1.7k
Australia
d-cameron1.7k 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 10 days ago • written 10 days ago by d-cameron1.7k
2
gravatar for cpad0112
10 days ago by
cpad01125.3k
cpad01125.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 10 days ago by cpad01125.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: 628 users visited in the last hour