zoukankan      html  css  js  c++  java
  • linux 系统中sed预存储技术 示例

    1、直接测试

    root@PC1:/home/test# ls
    a.fna
    root@PC1:/home/test# cat a.fna
    >NC_019458.2 Ovis aries breed Texel chromosome 1, Oar_v4.0, [whole genome shotgun sequence] ## 利用sed实现仅保留红色背景部分
    gataaaaaataaatagaaacaaaatcactgaagaaCCAGTGTGCCTGCTCAGGTCAGATGAAGCCAGAGGGCTGCCAGAG
    GGCAAGCGAGCTGCGTTGCCTGGAAAAAGTTAAACACACAGAGAGCATGGTGGCTCTGATACTTTCTAGAAGGATTAAAG
    TCACTTTCCCAGTCTTTATGAGAATTGGGCCGAAGCTTAGCTGGTGCAACGAATTTAGAAATGAATGCACTTGCATTTGA
    >NC_019458.2 Ovis aries breed Texel chromosome 1, Oar_v4.0, [whole genome shotgun sequence]
    AGATGATGTGTCTTTGCCTTGAgctaaaaattttagaataatctgaACGTCATCTGAGGAACCTGCTTCTGGCGTGGTTT
    TGGTGTCAGCATCTTCTCACCCTCTCTAGTAATTTTCAGTATGCATTTCTATTTTCGTGTAGTTATTTACAGGAGCATTT
    TATGGAAAACCGGCTCAAATCTTTTTGGGTGCAGGGGTAGTTCAAATGCACTGAGACCCTCAGTTTCACTTGCTAATCTC
    >NC_019458.2 Ovis aries breed Texel chromosome 1, Oar_v4.0, [whole genome shotgun sequence]
    CTCCAGAAACCCTGTTCTCCTCGAGTGACAAGGTCAGCAGGGCAGCACGTGTGTTCCTGTCACTGCCAACTCAAGAATAT
    GAAGTTTAAAGAGTTTCACCATCAAATGCAGTGTCGTGGACTGCCCCTGAACAGGTGTTTATAATCACGTGTGCAAGTGA
    AGCAAGCACAAATCCTCAGTGGAAAACGGGCAGAGGACACGAGCagacaattctttttaaaaactgcacaaATTAGCACA
    >NC_019458.2 Ovis aries breed Texel chromosome 1, Oar_v4.0, [whole genome shotgun sequence]
    CTAGGCACGGATGAGCGTGCCTACCGTGTTGCATGGAGGTAACAGATGCCAGAGCCCGGAGGAGGCGCAAAGCTCACAAA
    CAGATGCGGACCGCAGGAAGCCGGGACGGCCTTCCTCCCCTGAAGCAGGAGGACGCGCCCTACAGAAAGCCGCTCGATCC
    TCCAGGCATTTGTTGTGAGCACTTAATCATCATTCGATCATTTGACGTGTACTCACTAGTAAAAGGCAGGACTGTGTCCC
    root@PC1:/home/test# sed 's/\(>[^\s]\+\)\s.*\(\[.*\]\)/\1 \2/' a.fna  ##使用正则表达式,第一个小括号被保存在\1中,第二个小括号被保存在\2中
    >NC_019458.2 [whole genome shotgun sequence]
    gataaaaaataaatagaaacaaaatcactgaagaaCCAGTGTGCCTGCTCAGGTCAGATGAAGCCAGAGGGCTGCCAGAG
    GGCAAGCGAGCTGCGTTGCCTGGAAAAAGTTAAACACACAGAGAGCATGGTGGCTCTGATACTTTCTAGAAGGATTAAAG
    TCACTTTCCCAGTCTTTATGAGAATTGGGCCGAAGCTTAGCTGGTGCAACGAATTTAGAAATGAATGCACTTGCATTTGA
    >NC_019458.2 [whole genome shotgun sequence]
    AGATGATGTGTCTTTGCCTTGAgctaaaaattttagaataatctgaACGTCATCTGAGGAACCTGCTTCTGGCGTGGTTT
    TGGTGTCAGCATCTTCTCACCCTCTCTAGTAATTTTCAGTATGCATTTCTATTTTCGTGTAGTTATTTACAGGAGCATTT
    TATGGAAAACCGGCTCAAATCTTTTTGGGTGCAGGGGTAGTTCAAATGCACTGAGACCCTCAGTTTCACTTGCTAATCTC
    >NC_019458.2 [whole genome shotgun sequence]
    CTCCAGAAACCCTGTTCTCCTCGAGTGACAAGGTCAGCAGGGCAGCACGTGTGTTCCTGTCACTGCCAACTCAAGAATAT
    GAAGTTTAAAGAGTTTCACCATCAAATGCAGTGTCGTGGACTGCCCCTGAACAGGTGTTTATAATCACGTGTGCAAGTGA
    AGCAAGCACAAATCCTCAGTGGAAAACGGGCAGAGGACACGAGCagacaattctttttaaaaactgcacaaATTAGCACA
    >NC_019458.2 [whole genome shotgun sequence]
    CTAGGCACGGATGAGCGTGCCTACCGTGTTGCATGGAGGTAACAGATGCCAGAGCCCGGAGGAGGCGCAAAGCTCACAAA
    CAGATGCGGACCGCAGGAAGCCGGGACGGCCTTCCTCCCCTGAAGCAGGAGGACGCGCCCTACAGAAAGCCGCTCGATCC
    TCCAGGCATTTGTTGTGAGCACTTAATCATCATTCGATCATTTGACGTGTACTCACTAGTAAAAGGCAGGACTGTGTCCC

    2、简单示例

    root@PC1:/home/test# echo "hello world" | sed 's/\(hello\).*/world \1/'  ##hello存储在\1中,匹配了完整的hello world,因此替换为 world hello
    world hello

    3、示例3

    root@PC1:/home/test# cat mysed.txt    ## 在第一个Beijing和第4个Beijing后面添加2008
    Beijing Beijing Beijing Beijing
    London London London London
    root@PC1:/home/test# sed 's/\(^Beijing\)\(.*\)\(Beijing$\)/\1 2008\2\3 2008/' mysed.txt 
    Beijing 2008 Beijing Beijing Beijing 2008
    London London London London

     参考:http://c.biancheng.net/linux/sed.html

  • 相关阅读:
    JAVA005-基本数据类型变量的存储
    JAVA003-变量、数据类型
    Python_pandas数据处理_学习
    python_性能FPS
    DB_004_创建表
    DB_003_关系数据库标准语言(SQL)
    DB_002_数据库的创建和管理
    DB_001_概念模型设计
    虚幻蓝图学习笔记 简单VR功能实现
    虚幻蓝图学习笔记 制作第一人称(实现功能:捡枪,换枪,扔枪,仍炸弹等)(一)
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/15586072.html
Copyright © 2011-2022 走看看