reduce size of string
2
0
Entering edit mode
3.4 years ago
Jason • 0

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 • 627 views
3
Entering edit mode
3.4 years ago
d-cameron ★ 2.3k

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

2
Entering edit mode
3.4 years ago

output:

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


input:

\$ cat test.txt
abcdtmrtnunzaeq
ygbwwqwtsazpklf
yuncspytaqwercl