Skip to content

Commit 10cffde

Browse files
authored
cat: line number compat (#442)
* When printing line number prefix for -n and -b flags, terminate the line number with a tab character * This makes the output compatible with the OpenBSD and GNU versions * Flags -n and -b are not covered in standards document [1] * Line number can be printed directly without modifying the value of line buffer $_ * Now md5sum matches for /bin/cat -n and -b output on my linux system 1. https://pubs.opengroup.org/onlinepubs/9699919799/utilities/cat.html
1 parent bc9de7f commit 10cffde

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

bin/cat

+3-3
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@ sub do_file {
7878
$was_empty = $is_empty;
7979
}
8080

81-
$_ = sprintf "%6d %s", ++ $count, $_ if $number_lines ||
82-
$number_non_blanks && /\S/;
83-
8481
s/$/\$/ if $ends;
8582
if ($nonprinting) {
8683
s/([\x80-\xFF])/"M-" . ("\x7F" & $1)/ge;
@@ -91,6 +88,9 @@ sub do_file {
9188
s/\x09/^I/g;
9289
}
9390

91+
if ($number_lines || ($number_non_blanks && /\S/)) {
92+
printf "%6d\t", ++$count;
93+
}
9494
print;
9595
}
9696
if ($name ne '-' && !close($fh)) {

0 commit comments

Comments
 (0)