奇妙な色出力

奇妙な色出力

私の写真がすべて含まれているディスクで重複した写真を見つけようとしています。そのために、重複する可能性のあるファイルを作成しました(いくつかのEXIFとチェックサム属性を使用しましたが、これは質問の目的ではありません)。

私はこの形式を使用してファイルを作成しました(主にEXIFtoolといくつかの形式を使用)。

./PICTURES_archives/organizer/Ipad/823WGTMA/IMG_1777.JPG <--> ./PICTURES_archives/organizer/Ipad/965YOKDJ/IMG_2346.JPG

./PICTURES_archives/a Organizer/iCloud Photos/マイフォトストリーム/IMG_0954.JPG <--> ./Pictures A classer/Iphone 5S Icloud/IMG_0954.JPG

awk同じ出力を異なる形式で表示するために、次のスクリプトを作成しました。

awk -F'<-->' 'BEGIN {
                format1= "%25s %-50s\n"; 
                format2 = "%-50s %s\n";
                compt=1 
              } 
              {
                compt++; 
                split($1,a,"/"); 
                split($2,b,"/"); 
                longb=length(b);
                longa=length(a); 
                long=longb; 
                if (longa>longb) long=longa; 
                for(i=1; i<=long;i++) {
                    if(a[i]==b[i]) printf format1,"    ",  a[i] ; 
                    else printf format2, a[i],b[i]
                } 
                print "\n"
              }' identical.txt 

私にとってもっと読みやすいです。出力は次のとおりです

アーカイブ 共通パス ファイルb
写真_アーカイブ
組織
タブレット
823WGTMA 965YOKDJ
IMG_1777.JPG IMG_2346.JPG
写真_アーカイブ PictureA Classer
組織 iPhone 5Sクラウドドライブ
iCloudの写真 IMG_0954.JPG
マイフォトストリーム
IMG_0954.JPG

問題:ファイルaとbが異なる情報を持っているときに出力に色を追加したいと思います。

printf format2, "\033[33m"a[i] "\033[0m","\033[33m"b[i] "\033[0m"

but it shows me the following output

ESC[33m823WGTMAESC[0m                                  ESC[33m965YOKDJESC[0m
ESC[33mIMG_1777.JPG ESC[0m                             ESC[33mIMG_2346.JPGESC[0m

ESC[33mは色として解釈されません。

どのようなヒントがありますか?

オペレーティングシステム: Darwin macOS Big Sur

ベストアンサー1

問題は、出力をパイピングしてlessおり、less基本的にこれらのエスケープシーケンスが解釈されないことです。しかし、使用するとうまく動作しますless -R。これに関する文書は次のとおりですman less

       -R or --RAW-CONTROL-CHARS
              Like -r, but only ANSI "color" escape sequences and OSC  8  hy‐
              perlink  sequences  are  output  in "raw" form.  Unlike -r, the
              screen appearance is maintained correctly, provided that  there
              are  no  escape sequences in the file other than these types of
              escape sequences.  Color escape sequences  are  only  supported
              when  the  color  is changed within one line, not across lines.
              In other words, the beginning of each line  is  assumed  to  be
              normal  (non-colored),  regardless  of  any escape sequences in
              previous lines.  For the purpose of keeping track of screen ap‐
              pearance,  these  escape  sequences are assumed to not move the
              cursor.

おすすめ記事