brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: sponge lets a terminal pipeline write back to its own input file

Terminal
~/tips/tip-terminal-sponge-rewrite-same-file

sort -u list.txt | sponge list.txt

Writes a pipeline's result back to the file it was reading from.

Redirecting a pipeline into the file it reads empties the file first.

sort -u list.txt | sponge list.txt

With sort -u list.txt > list.txt the shell truncates the file before sort reads it. sponge soaks up all input and only then writes the file. It comes with the moreutils package. Use sponge -a to append. The data sits in memory or a temporary file until the input ends, so a failing earlier command can still overwrite the file with partial output.

Further reading: sponge manual page

More Terminal tips ioreg -rn AppleSmartBattery | grep CycleCount Terminal can save your windows and tabs as a window group Export a Terminal profile to a .terminal file and import it on another Mac mc hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x700000029}]}' All Terminal tips (116) All topics

Link