terraform planの結果のエスケープシーケンス

terraform planの結果をファイルへ保存するとエスケープシーケンスが残ってしまう。

$ terraform plan > plan.txt
$ less plan
ESC[0mESC[1mdata.aws_iam_policy_document.instance_profile_assume_role: Reading...ESC[0mESC[0m
ESC[0mESC[1mdata.aws_iam_policy_document.instance_profile_assume_role: Read complete after 0s [id=1903849331]ESC[0m

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  ESC[32m+ESC[0m create
ESC[0m
Terraform will perform the following actions:
.
.
.

terraform plan -no-colorでエスケープシーケンスを消す

-no-colorオプションを付加するとエスケープシーケンスが消える。

$ terraform plan -no-color > plan.txt
$ less plan.txt
data.aws_iam_policy_document.instance_profile_assume_role: Reading...
data.aws_iam_policy_document.instance_profile_assume_role: Read complete after 0s [id=1903849331]

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:
.
.
.

エスケープシーケンスが残った状態でlessで見るには-rオプションを使う

less-rオプションを使うとエスケープシーケンスが残った状態で表示できる。

$ less -r plan.txt

以下のようにエスケープシーケンスを解釈して色付きで表示される。

less -r