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 } }'
이것은 나에게 효과적입니다.