I am using fswatch to refresh refreshed.txt when watched.txt is modified. Currently, something is appended to the refreshed.txt.
fswatch -o watched.txt | xargs -n1 sh -c "echo 'something' >> refreshed.txt"
However, I want to write something and then delete it.
I have tried:
fswatch -o watched.txt | xargs -n1 sh -c "echo 'something\b\b' >> refreshed.txt"
and
fswatch -o watched.txt | xargs -n1 sh -c "echo 'something' >> refreshed.txt && sed -ie '$d' refreshed.txt"
but neither seem to achieve the desired effect.
The sed is not run, because when you feed you
"quoted script tosh, $d is replaced with an empty string:You should escape
$, to avoid that:Note that adding a line and then immediately removing it, would be pretty much an equivalent of simply updating it's modification timestamp, so you may want to make it sleep for a bit, for the change detection system to catch on.