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: cat -A shows the tabs, line endings and odd characters you cannot see

Shell
~/tips/tip-shell-cat-a-show-hidden-chars

cat -A docker-compose.yml

Prints a file with tabs, line ends and control characters made visible.

A config file that looks perfect and still fails usually has an invisible culprit: a tab where spaces belong, or a Windows line ending.

cat -A prints a file with the invisible parts spelled out. The man page says it is equivalent to -vET: -E displays $ or ^M$ at the end of each line, -T shows tabs as ^I, and -v uses ^ and M- notation for other non-printing characters.

cat -A docker-compose.yml

Say the output looks like this:

services:^M$
^Iweb:$
  image: nginx   $

The first line ends in ^M$, so it has a carriage return from a Windows line ending. The second line starts with ^I, a tab, which YAML does not accept for indentation. On the last line the spaces before the $ are trailing whitespace that you could not see before.

Seeing the problem is half of it. To fix the line endings you still need something like dos2unix, or sed -i 's/\r$//' file. Make a copy first, since sed -i edits the file in place.

This is the GNU cat option. The cat on macOS may not know -A, and cat -et gives similar output there. For a huge file, pipe it through less or head, because every character gets a notation and the output grows.

Further reading: cat(1) manual page

More Shell tips zmv -n '(*).log' '$1.txt' zoxide query -ls project f=$(mktemp --suffix=.json) shopt globskipdots echo $EPOCHSECONDS All Shell tips (78) All topics

Link