bash sponge - ghdrako/doc_snipets GitHub Wiki
Unlike a shell redirect, sponge soaks up all its input before opening the output file. This allows constricting pipelines that read from and write to the same file.
sudo apt-get install moreutils
grep -v 'seg[0-9]\{1,\}\.[0-9]\{1\}' file_name | sponge file_name