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ELAFATQQFVALQLIAEDLDETSDPALLARCSDFFIEHSQYERAVELLLAARKYQEALQLCLGQNMSITEEMAEKMTVAKDSSDLPEESRRELLEQIADCCMRQGSYHLATKKYTQAGNKLKAMRALLKSGDTEKITFFASVSRQKEIYIMAANYLQSLDWRKEPEIMKNIIGFYTKGRALDLLAGFYDACAQVEIDEYQNYDKAHGALTEAYKCLAKAKAKSPLDQETRLAQLQSRMALVKRFIQARRTYTEDPKESIKQCELLLEEPDLDSTIRIGDVYGFLVEHYVRKEEYQTAYRFLEEMRRRLPLANMSYYVSPQAVDAVHRGLGLPLPRTVPEQVRHNSMEDARELDEEVVEEADDDP
我想将索引位置383 (Q)替换为后面没有任何内容,因此期望的结果将是:
MALYYDHQIEAPDAAGSPSFISWHPVHPFLAVAYISTTSTGSVDIYLEQGECVPDTHVERPFRVASLCWHPTRLVLAVGWETGEVTVFNKQDKEQHTMPLTHTADITVLRWSPSGNCLLSGDRLGVLLLWRLDQRGRVQGTPLLKHEYGKHLTHCIFRLPPPGEDLVQLAKAAVSGDEKALDMFNWKKSSSGSLLKMGSHEGLLFFVSLMDGTVHYVDEKGKTTQVVSADSTIQMLFYMEKREALVVVTENLRLSLYTVPPEGKAEEVMKVKLSGKTGRRADIALIEGSLLVMAVGEAALRFWDIERGENYILSPDEKFGFEKGENMNCVCYCKVKGLLAAGTDRGRVAMWRKVPDFLGSPGAEGKDRWALQTPTELQGNITQ
I have try:
sed 's/"Q"//383' text.file
sed 's/Q//383' text.file
但这没有任何作用。
从长远来看,我需要做一些其他的职位,所以一个灵活的方法将是非常感激的。
祝一切顺利
这可能适合您(GNU sed):
sed -zEi 's/(.{383}).*/1/' file
存储前383个字符作为反向引用,并删除其余字符。
注意:-z
选项将整个文件吸进内存。
你可以使用cut:
cut -c 1-383 < text.file
GNU awk:
gawk '{print gensub(/(.{383}).*/,"\1","1")}' file
只是把它扔到池中,head
可以用来切断n
行之后,也可以切断c
字节之后:
$ head -c 383 text.file
如果您将字符串存储在bash变量中,则可以使用bash参数扩展:
mystring=$(cat text.file)
echo "${mystring:0:383}"
另一个选项:dd
dd if=txt.file bs=383 count=1 status=none
使用bash
和printf
:
printf '%.383sn' $(<text.file)