Use zcat and sed or awk to edit compressed .gz text file

前端 未结 2 1027
梦如初夏
梦如初夏 2020-12-29 11:05

I am trying to edit compressed fastq.gz text files, by removing the first six characters of lines 2,6,10,14... I have two different ways of doing this right now, either usin

2条回答
  •  鱼传尺愫
    2020-12-29 11:40

    You can't bypass compression, but you can chain the decompress/edit/recompress together in an automated fashion:

    for f in /dir/*; do
      cp "$f" "$f~" &&   
      gzip -cd "$f~" | sed '2~4s/^.\{6\}//' | gzip > "$f"
    done
    

    If you're quite confident in the operation, you can remove the backup files by adding rm "$f~" to the end of the loop body.

提交回复
热议问题