LinuxのCSVファイルでは、「失敗」という単語で始まる最新の列がnullでない場合にのみテーブルを印刷したいと思います。
私の意見 -
Name,Mon,Tue,Wed,Thu,Fri,Mon
Linux,Successfull Fullbackup; Failed Fullbackup,,,,,Failed Fullbackup
Unix,,,,Failed Fullbackup,,
Windows,Failed Fullbackup,Failed Fullbackup,Failed Fullbackup,Failed Fullbackup,Failed Fullbackup,Successfull Fullbackup
MAC,Failed Fullbackup,Failed Fullbackup,Failed Fullbackup,Failed Fullbackup,Failed Fullbackup,Failed Fullbackup
Solaris,Failed Fullbackup,Failed Fullbackup,Failed Fullbackup,Successfull Fullbackup; Failed Fullbackup,,
私の出力は次のようになります
Name,Mon,Tue,Wed,Thu,Fri,Mon
Linux,Successfull Fullbackup; Failed Fullbackup,,,,,Failed Fullbackup
Unix,,,,Failed Fullbackup,,
MAC,Failed Fullbackup,Failed Fullbackup,Failed Fullbackup,Failed Fullbackup,Failed Fullbackup,Failed Fullbackup
答え1
sed -e 1b -e $'/[\t,]Failed[^\t,]*[\t,]*$/!d'
答え2
何の内容なのかはよくわかりませんが、行が長すぎて説明しにくいです。だから私はこうしました:
sed 's/,S[^,]*/,A/g;s/,Fa[^,]*/,F/g
' <<\DATA
Name,Mon,Tue,Wed,Thu,Fri,Mon
Linux,Successfull Fullbackup; Failed Fullbackup,,,,,Failed Fullbackup
Unix,,,,Failed Fullbackup,,
Windows,Failed Fullbackup,Failed Fullbackup,Failed Fullbackup,Failed Fullbackup,Failed Fullbackup,Successfull Fullbackup
MAC,Failed Fullbackup,Failed Fullbackup,Failed Fullbackup,Failed Fullbackup,Failed Fullbackup,Failed Fullbackup
Solaris,Failed Fullbackup,Failed Fullbackup,Failed Fullbackup,Successfull Fullbackup; Failed Fullbackup,,
DATA
出力
Name,Mon,Tue,Wed,Thu,Fri,Mon
Linux,A,,,,,F
Unix,,,,F,,
Windows,F,F,F,F,F,A
MAC,F,F,F,F,F,F
Solaris,F,F,F,A,,
あなたの質問に答えるかどうかはわかりませんが、読みやすくなりました。成績表は理解しています。しかし、誰かがそのMacを実際に見なければなりません。可能性が大きすぎます...
答え3
利用可能な場合perl
:
$ perl -F',' -anle 'print if $. == 1 or (grep {$_} @F)[-1] =~ /^Failed/' file
Name,Mon,Tue,Wed,Thu,Fri,Mon
Linux,Successfull Fullbackup; Failed Fullbackup,,,,,Failed Fullbackup
Unix,,,,Failed Fullbackup,,
MAC,Failed Fullbackup,Failed Fullbackup,Failed Fullbackup,Failed Fullbackup,Failed Fullbackup,Failed Fullbackup
答え4
$ cat file | awk -F"," \
'{for ( x=NF ; x>1 ; x-- ) { if ( $x ~ /^Failed/ ) { x = 0 ; print } ; \
if ( $x ~ /^Successful/ ) x = 0 } }'
これは私にとって効果的です。