違いのみを記録するには、watch -dコマンドを使用してください。

違いのみを記録するには、watch -dコマンドを使用してください。

watch新しいバージョンファイルと古いバージョンファイルの違いをファイ​​ル(doc.txt)に書き込むために使用する必要があります。

試してみましたが、コマンドを使用してwatch -t -d -n 10 "cat myfile.txt | tee doc.txt"すべてのmyfile.txtテキストが端末に書き込まれ、cat違いのみが強調表示されました。そして、私はdoc.txtmyfile.txtと同じ内容があります。

どんなアイデアがありますか?

ベストアンサー1

管理人が言った

watch - execute a program periodically, showing output fullscreen

どこ

 -n, --interval seconds
              Specify  update  interval.   The command will not allow quicker
              than 0.1 second interval, in which the smaller values are  con‐
              verted. Both '.' and ',' work for any locales.



 -d, --differences [permanent]
              Highlight the differences between successive  updates.   Option
              will read optional argument that changes highlight to be perma‐
              nent, allowing to see what has  changed  at  least  once  since
              first iteration.       
 -t, --no-title
              Turn off the header showing the interval, command, and  current
              time  at the top of the display, as well as the following blank
              line.

猫の人が言う

 cat - concatenate files and print on the standard output

Tシャツを着た男が言う

tee - read from standard input and write to standard output and files

これはうまくいくかもしれません

10秒ごとにdoc.txtの2つのバージョン間の違いを観察し、それをdoc.txtファイルに書き込みます。

watch -t -d doc.txt -n 10 | tee new.txt

おすすめ記事