0

I read a text file with names in it. When some conditions are true, I remove the name (a whole line) from the list, with

grep -v $var $list.txt > $list.tmp; mv $list.tmp $list.txt

But I have multiple scripts doing the same thing on the same list, but at different positions. Can it be harmful if two scripts try to edit a line at the same time ? Do I have to add something ? Cheers

Cyrus
  • 84,225
  • 14
  • 89
  • 153
UltimeCactus
  • 73
  • 1
  • 6
  • Yes. Use a database for this. – Cyrus Oct 14 '20 at 11:02
  • Yes, it appears that your code is prone to race conditions. Try to add a lock condition. – tripleee Oct 14 '20 at 11:02
  • A better approach altogether is to collect a list of all the strings you want to remove, then change the file just once. This should be significantly more efficient as well; rewriting the same data many times is the main bottleneck here. Try `grep -v -e string1 -e string2` or `grep -vF patternfile` or refactor to a simple `sed` script. – tripleee Oct 14 '20 at 11:07

0 Answers0