Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

TAIL counts lines differently based on character encoding

Charles Dye

Super Moderator
May
4,923
126
Staff member
Code:
C:\>option //unicodeoutput=no

C:\>setdos | tail /n 4
PARAMETERS=$
CURSOR OVERSTRIKE=100
CURSOR INSERT=15
VERBOSE=1

C:\>option //unicodeoutput=yes

C:\>setdos | tail /n 4
CURSOR OVERSTRIKE=100
CURSOR INSERT=15
VERBOSE=1

C:\>option //unicodeoutput=no

C:\>setdos | tail /n 4
PARAMETERS=$
CURSOR OVERSTRIKE=100
CURSOR INSERT=15
VERBOSE=1

C:\>

One of my "bugs nobody cares about" involved @EXECSTR[-n,command] sometimes returning a 'phantom' blank line. After @ClioCJS's post about @EXECSTR failing if you alias TAIL, it has dawned on me that this is actually an oddity of TAIL. If the input text is UTF-16 and the last line ends in CR/LF (possibly other line-ends too; I haven't checked), then TAIL infers a final empty line. This does not happen with ANSI or UTF-8 input.
 
Code:
C:\>option //unicodeoutput=no

C:\>setdos | tail /n 4
PARAMETERS=$
CURSOR OVERSTRIKE=100
CURSOR INSERT=15
VERBOSE=1

C:\>option //unicodeoutput=yes

C:\>setdos | tail /n 4
CURSOR OVERSTRIKE=100
CURSOR INSERT=15
VERBOSE=1

C:\>option //unicodeoutput=no

C:\>setdos | tail /n 4
PARAMETERS=$
CURSOR OVERSTRIKE=100
CURSOR INSERT=15
VERBOSE=1

C:\>

One of my "bugs nobody cares about" involved @EXECSTR[-n,command] sometimes returning a 'phantom' blank line. After @ClioCJS's post about @EXECSTR failing if you alias TAIL, it has dawned on me that this is actually an oddity of TAIL. If the input text is UTF-16 and the last line ends in CR/LF (possibly other line-ends too; I haven't checked), then TAIL infers a final empty line. This does not happen with ANSI or UTF-8 input.

Oh neat! Perhaps you could just alias tail to call tail.bat (i do this with a lot of internal/unix commands to add stuff to them)

and then have that issue fixed there

maybe even return one extra line to ensure you get something, and then destroy the top line if you get more than one line. maybe something with sed doing a regex , i dunno
 
Fixed in build 20. (Also fixes the very obscure bug in which %@EXECSTR[-1,command] when //UnicodeOutput=Yes sometimes returns a phantom blank line.)
 

Similar threads

Back
Top