Today I Learned how to remove lines from a file which is sorted. In particular, I wanted to apply that knowledge to filter the list of already installed Homebrew casks (generated with `brew list --cask`) from the list of casks that I had installed in a a previous version (`20251201.previously_installed_casks.txt`). The list of casks pending installation then can be obtained by typing:
```bash
grep -Fxv -f <(brew list --cask) 20251201.previously_installed_casks.txt
```
(See https://explainshell.com/explain?cmd=grep+-Fxv+-f+%3C%28brew+list+--cask%29+20251201.previously_installed_casks.txt for a detailed explanation.)
That way, I can use the `--force` function to update my Homebrew cask database of installed items after manually upgrading Homebrew installation (from 4.5 to 5.0; for some reason it did not upgrade itself) but removing those items already installed:
```bash
brew install --force --cask $( grep -Fxv -f <(brew list --cask) 20251201.previously_installed_casks.txt )
```
Or this option, in case you want to go ahead with other items if any of the casks has problems:
```bash
for cask in $( grep -Fxv -f <(brew list --cask) 20251201.previously_installed_casks.txt)
do
echo; echo
echo "Installing: $cask"; echo
brew install --force --cask $cask
done
```
#TIL #TodayILearned #bash #zsh #grep #ExplainShell #Homebrew