[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
tee: add --remove-cr option
From: |
Nikos Papaspyrou |
Subject: |
tee: add --remove-cr option |
Date: |
Wed, 9 Feb 2022 03:59:41 +0100 |
I have implemented an option for tee which is helpful when one wants to
capture the output of a program that uses carriage return characters, to
visualize its progress. I am attaching the patch.
Motivation: Say we want to use the option "status=progress" for dd, in
order to keep track of the task's progress, but we also want to send
the program's output to a log file:
$ dd if=input of=output bs=64 status=progress |& tee LOG
40273024 bytes (40 MB, 38 MiB) copied, 3 s, 13,4 MB/s
805136+1 records in
805136+1 records out
51528755 bytes (52 MB, 49 MiB) copied, 4,04839 s, 12,7 MB/s
$ hexdump -C LOG
00000000 0d 31 33 32 36 34 34 34 38 20 62 79 74 65 73 20 |.13264448
bytes |
00000010 28 31 33 20 4d 42 2c 20 31 33 20 4d 69 42 29 20 |(13 MB, 13
MiB) |
00000020 63 6f 70 69 65 64 2c 20 31 20 73 2c 20 31 33 2c |copied, 1 s,
13,|
00000030 33 20 4d 42 2f 73 0d 32 36 37 37 34 35 39 32 20 |3
MB/s.26774592 |
00000040 62 79 74 65 73 20 28 32 37 20 4d 42 2c 20 32 36 |bytes (27 MB,
26|
00000050 20 4d 69 42 29 20 63 6f 70 69 65 64 2c 20 32 20 | MiB) copied,
2 |
00000060 73 2c 20 31 33 2c 34 20 4d 42 2f 73 0d 34 30 32 |s, 13,4
MB/s.402|
00000070 37 33 30 32 34 20 62 79 74 65 73 20 28 34 30 20 |73024 bytes
(40 |
00000080 4d 42 2c 20 33 38 20 4d 69 42 29 20 63 6f 70 69 |MB, 38 MiB)
copi|
00000090 65 64 2c 20 33 20 73 2c 20 31 33 2c 34 20 4d 42 |ed, 3 s, 13,4
MB|
000000a0 2f 73 0a 38 30 35 31 33 36 2b 31 20 72 65 63 6f |/s.805136+1
reco|
000000b0 72 64 73 20 69 6e 0a 38 30 35 31 33 36 2b 31 20 |rds
in.805136+1 |
000000c0 72 65 63 6f 72 64 73 20 6f 75 74 0a 35 31 35 32 |records
out.5152|
000000d0 38 37 35 35 20 62 79 74 65 73 20 28 35 32 20 4d |8755 bytes (52
M|
000000e0 42 2c 20 34 39 20 4d 69 42 29 20 63 6f 70 69 65 |B, 49 MiB)
copie|
000000f0 64 2c 20 34 2c 30 34 38 33 39 20 73 2c 20 31 32 |d, 4,04839 s,
12|
00000100 2c 37 20 4d 42 2f 73 0a |,7 MB/s.|
00000108
Notice that the LOG file contains more than can be seen in the standard
output. Three lines were printed with progress information, each starting
with a carriage return character (0d). Only the last one remained and can
be seen in the standard output. This is frustrating if one needs to edit
or otherwise process the LOG file.
With the proposed new option, progress information is shown in the
standard output but is not stored to the LOG file:
$ dd if=input of=output bs=64 status=progress |& tee --remove-cr LOG
40865344 bytes (41 MB, 39 MiB) copied, 3 s, 13,6 MB/s
805136+1 records in
805136+1 records out
51528755 bytes (52 MB, 49 MiB) copied, 4,01799 s, 12,8 MB/s
$ hexdump -C LOG
00000000 34 30 38 36 35 33 34 34 20 62 79 74 65 73 20 28 |40865344 bytes
(|
00000010 34 31 20 4d 42 2c 20 33 39 20 4d 69 42 29 20 63 |41 MB, 39 MiB)
c|
00000020 6f 70 69 65 64 2c 20 33 20 73 2c 20 31 33 2c 36 |opied, 3 s,
13,6|
00000030 20 4d 42 2f 73 0a 38 30 35 31 33 36 2b 31 20 72 | MB/s.805136+1
r|
00000040 65 63 6f 72 64 73 20 69 6e 0a 38 30 35 31 33 36 |ecords
in.805136|
00000050 2b 31 20 72 65 63 6f 72 64 73 20 6f 75 74 0a 35 |+1 records
out.5|
00000060 31 35 32 38 37 35 35 20 62 79 74 65 73 20 28 35 |1528755 bytes
(5|
00000070 32 20 4d 42 2c 20 34 39 20 4d 69 42 29 20 63 6f |2 MB, 49 MiB)
co|
00000080 70 69 65 64 2c 20 34 2c 30 31 37 39 39 20 73 2c |pied, 4,01799
s,|
00000090 20 31 32 2c 38 20 4d 42 2f 73 0a | 12,8 MB/s.|
0000009b
More specifically, lines ending with carriage return are sent to the
standard output but not to the files.
--
Nikolaos Papaspyrou
Software Engineer
nikolaos@google.com
Google Germany GmbH
Erika-Mann-Straße 33
80636 München
Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Diese E-Mail ist vertraulich. Falls Sie diese fälschlicherweise erhalten
haben sollten, leiten Sie diese bitte nicht an jemand anderes weiter,
löschen Sie alle Kopien und Anhänge davon und lassen Sie mich bitte wissen,
dass die E-Mail an die falsche Person gesendet wurde.
This e-mail is confidential. If you received this communication by mistake,
please don't forward it to anyone else, please erase all copies and
attachments, and please let me know that it has gone to the wrong person.
tee-remove-cr.patch
Description: Binary data
- tee: add --remove-cr option,
Nikos Papaspyrou <=
- tee: add --remove-cr option, Nikos Papaspyrou, 2022/02/09
- Re: tee: add --remove-cr option, Bernhard Voelker, 2022/02/09
- Re: tee: add --remove-cr option, Nikos Papaspyrou, 2022/02/09
- Re: tee: add --remove-cr option, Nikos Papaspyrou, 2022/02/09
- Re: tee: add --remove-cr option, Rob Landley, 2022/02/09
- Re: tee: add --remove-cr option, Nikos Papaspyrou, 2022/02/09
- Re: tee: add --remove-cr option, Bernhard Voelker, 2022/02/09
- Re: tee: add --remove-cr option, Nikos Papaspyrou, 2022/02/09
- Re: tee: add --remove-cr option, Rob Landley, 2022/02/09