ファイルテキストを一度に1ページずつ表示し、20秒待ってから自動的に進みます。

ファイルテキストを一度に1ページずつ表示し、20秒待ってから自動的に進みます。

この質問はAIX 7についてです。

私は複数ページのテキストを表示できるモニターに取り組んできました。最初に、エンドユーザーはスクロールリストを望んでおり、これについて以下を作成しました。

IFS=''; cat plfeed | while read line; do echo $line; perl -e 'select(undef,undef,undef,.8)'; done

エンドユーザーは、設定された時間(20秒など)内に1ページ(24行)の出力を表示することを決定します。より多くの情報を使用すると、一度に1ページずつ表示できますが、私のユースケースには許可されていないキーボード入力が必要であることがわかります。

ギイ;

「more」コマンドを自動化したり、ページ間で待機して自動的に進行する同様の機能を構築するにはどうすればよいですか?

答え1

これはかなり標準的awkで、AIXでは大丈夫でしょう。

awk '{if(NR>1 && NR%24==1)system("sleep 20");print}'

system()コメントで述べたように、中断時に終了するには

{if(system("sleep 20"))exit}

ただし、オペレーティングシステムでは機能しない可能性があります。

答え2

#!/usr/bin/env expect 
set timeout 20
spawn -noecho man autoexpect
while 1 {
  expect {
    timeout { send " " }
    -ex "(END)" { exit }
  }
}

答え3

awkこれは、同様の解決策を使用して同様の性質のOP問題を解決します。まあ。次のように変更しました。

  1. Ctrl+で終了しますc
  2. $LINES端末の高さを取得するために使用されます。
  3. Linux および Mac OSX で使用できます。
  4. ドキュメントと説明を追加しました。
awk -v x=$LINES 'NR % x == 0 && system("sleep 20"){exit} 1'
#    ^^^^^^^^^^  ^  ^^^^^^^^      ^                      ^
#       |        |  |             |                      |
#       |        |  |             |                      |
#       |        |  |             |                      +
#       |        |  |             |   f) pattern-action block which
#       |        |  |             |      prints the current line.
#       |        |  |             |        - Pattern is Truethy.
#       |        |  |             |        - Action is empty
#       |        |  |             |          defaulting to `{print}`
#       |        |  |             |
#       |        |  |             +
#       |        |  |   d) `system` function returns exit code `0` when
#       |        |  |       successful and non-zero on 'ctrl-c'.
#       |        |  |
#       |        |  |   e) `0` evaluates to false, so `exit` will not
#       |        |  |       execute until `ctrl-c` is triggered.
#       |        |  +
#       |        | c) When line number is evenly divisible
#       |        |    by x (the terminal height)
#       |        |    sleep for 1 second.
#       |        | 
#       |        | 
#       |        +
#       |   b) NR current line number.
#       |
#       +
# a) Set variable `x` to Bash variable $LINES.
#    $LINES is set to height of current terminal.

関連情報