How to edit 300 GB text file (genomics data)?

后端 未结 4 1351
旧巷少年郎
旧巷少年郎 2020-12-18 06:34

I have a 300 GB text file that contains genomics data with over 250k records. There are some records with bad data and our genomics program \'Popoolution\' allows us to comm

4条回答
  •  眼角桃花
    2020-12-18 07:28

    Based on your update:

    One more thought... Is there an approach that would allow us to add the asterisk to the line without opening the entire text file at once. This could be very useful given that we will have to repeat the process an unknown number of times.

    Here you have an approach: If you know the line number, you can add an asterisk in the beginning of that line saying:

    sed 'LINE_NUMBER s/^/*/' file
    

    See an example:

    $ cat file
    aa
    bb
    cc
    dd
    ee
    $ sed '3 s/^/*/' file
    aa
    bb
    *cc
    dd
    ee
    

    If you add -i, the file will be updated:

    $ sed -i '3 s/^/*/' file
    $ cat file
    aa
    bb
    *cc
    dd
    ee
    

    Even though I always think it's better to do a redirection to another file

    sed '3 s/^/*/' file > new_file
    

    so that you keep intact your original file and save the updated one in new_file.

提交回复
热议问题