reduce size of string
2
0
Entering edit mode
5.9 years ago
Jason ▴ 10

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 • 974 views
ADD COMMENT
3
Entering edit mode
5.9 years ago
d-cameron ★ 2.9k

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 COMMENT
2
Entering edit mode
5.9 years ago

output:

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

input:

$ cat test.txt 
abcdtmrtnunzaeq
ygbwwqwtsazpklf
yuncspytaqwercl
ADD COMMENT

Login before adding your answer.

Traffic: 1474 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6