I'm looking for a program to copy stdin to stdout while showing control characters (like cat -v
) and without waiting for an EOF (the input is from a tail -f
). I have GNU|Linux; the cat
that's installed ignores the -u
flag.
2 Answers
GNU cat
ignores -u
because its output is always unbuffered. So, when you ask for unbuffered output with -u
, you get it (but you also get it even when you don't ask for it).
GNU tail
has the same, always-unbuffered behaviour.
To prove this, in one shell I did:
while :; do echo -ne "hello\t"; sleep 1;done > testtail
which appends the word 'hello' followed by a tab, every second (with no newlines)
In another shell I did (cat -T
is similar to cat -v
-- it shows tabs as ^I):
tail -f testtail | cat -T
which gives me:
hello^Ihello^Ihello^Ihello^I ...
updated every second.
-
Thank you for this! Just to check, is there a primary source by which we could confirm this? I looked at the man page for
cat
on my system (Ubuntu) but didn't see anything. Aug 3, 2020 at 18:29 -
For reference: gnu.org/software/coreutils/manual/html_node/… - I do see indirect evidence from
stdbuf
s man pages: gnu.org/software/coreutils/manual/html_node/… - "uses the ISO C FILE streams for input/output (note the programs dd and cat don’t do that)" Aug 3, 2020 at 18:31
BSD cat
's -u
option disabled output buffering. From man cat
:
-u Disable output buffering.
-
According to the man page on this machine,
-u
is ignored. Sep 29, 2012 at 11:21 -
-
Nope, it's GNU
cat
(or whichever version is standard on Ubuntu). I guess I should've been more specific… Sep 30, 2012 at 12:08