輸入文件-test1
Failed ,abc, /clients/FORD_1030PM_EST_Windows2008, Windows File System
Failed ,abc, /clients/FORD_1030PM_EST_Windows2008 ,Windows File System
Completed, abc /clients/FORD_1030PM_EST_Windows2008, Windows File System
Failed ,def ,/clients/FORD_1030PM_EST_Windows2008 ,Windows File System
Failed ,def ,/clients/FORD_1030PM_EST_Windows2008 ,Windows File System
Failed ,def ,/clients/FORD_1030PM_EST_Windows2008 ,Windows File System
Failed ,ghi ,/clients/FORD_1030PM_EST_Windows2008, Windows File System
Failed ,jkl ,/clients/FORD_1030PM_EST_Windows2008 ,Windows File System
Completed ,def ,/clients/FORD_1030PM_EST_Windows2008, Windows File System
Completed ,hkm ,/clients/FORD_1030PM_EST_Windows2008 Windows File System
預期產出
Failed ghi, /clients/FORD_1030PM_EST_Windows2008, Windows File System
Failed jkl, /clients/FORD_1030PM_EST_Windows2008, Windows File System
代碼
sed -n '/Completed/ s,\(.*\) .* Completed$,\1,a' "$pwd"/test1 | grep -v -f - "$pwd"/test1
我想獲取只有失敗值的列,或者它們在任何行中都沒有完成。
如果awk
是您的選擇,請您嘗試:
awk '
/^Failed/ {gsub(/,/, "", $2); fail[$2]=$0} # if failed, store the line
/^Completed/ {gsub(/,/, "", $2); delete fail[$2]} # if completed, abandon the line from the list
END {for (i in fail) print fail[i]} # finally print the remaining list
' file
輸出:
Failed jkl ,/clients/FORD_1030PM_EST_Windows2008 ,Windows File System
Failed ghi ,/clients/FORD_1030PM_EST_Windows2008, Windows File System
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句