[英]How to compare the output of two binary files when the input is redirected to a file?
[英]compare two files and store the output in a file only if there is a mismatch
我在一個while循環中比較多個文件,並將輸出存儲在新文件中。
我在下面做
while IFS='|' read -r work_table_name final_table_name;do
comm -23 <(sort /home/$USER/work_schema/${work_table_name}_work_schema.txt) <(sort /home/$USER/final_schema/${final_table_name}_final_schema.txt) > /home/$USER/mismatched_schema/${final_table_name}.txt
done < /home/$USER/tables.txt
我得到我想要的。 但是只需要整個while
循環的一點結果。
我只想在文件之間不匹配時創建文件。 如果沒有不匹配,則根本不要創建文件。
我該如何實現?
但是只需要整個while循環的一點結果。
因此,重定向整個while循環輸出:
while read -r ....; do
comm -23 <(...) <(...)
done < input > output
或附加:
# this will truncate the output file, so we start empty
: > output
while read -r ....; do
comm -23 <(...) <(...) >> output
done < input
我基本上不想在比較兩個文件時創建一個空文件
因此,請檢查是否為空...
out=$(comm -23 <(....) <(....))
if ((${#out} != 0)); then
printf "%s" "$out"
fi
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.