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: tr -s ' ' makes cut work on aligned terminal columns

Terminal
~/tips/tip-terminal-tr-squeeze-cut-columns

df -h | tr -s ' ' | cut -d' ' -f1,5

Squeezes repeated spaces so cut can pick columns from padded output.

Command output padded with several spaces confuses cut, which counts every space as a field.

df -h | tr -s ' ' | cut -d' ' -f1,5

tr -s ' ' squeezes every run of spaces to one, so each column becomes a single field. Then cut -d' ' -f1,5 picks the first and fifth. For fields that contain spaces, such as the final column of ps, awk is a better choice. The squeeze trick does not help with tab-separated data.

Further reading: tr 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