samedi 21 février 2015

grep for a line in a file then remove the line


$ cat example.txt


Yields:



example
test
example


I want to remove 'test' string from this file.



$ grep -v test example.txt > example.txt
$ cat example.txt
$


The below works, but I have a feeling there is a better way!



$ grep -v test example.txt > example.txt.tmp;mv example.txt.tmp example.txt
$ cat example.txt
example
example


Worth noting that this is going to be on a file with over 10,000 lines.


Cheers


Aucun commentaire:

Enregistrer un commentaire