
안녕하세요. 다음과 같은 파일이 포함된 비슷한 폴더가 있습니다 /mell/908
.
cf-mell-pos-908-tcg-4619e.txt
cf-mell-pos-908-tcw-4619e.txt
cf-mell-pos-908-usc-4619e.txt
cf-mell-pos-908-wi_board-4619e.txt
copper_qnt
tcg_mell_upload_lx.txt
tcw_mell_upload_lx.txt
usc_mell_upload_lx.txt
wi_board_mell_upload_lx.txt
diff
명령을 사용하여 해당 파일을 비교하는 방법이 있습니까?
cf-mell-pos-908-tcg-4619e.txt
그리고tcg_mell_upload_lx.txt
cf-mell-pos-908-tcw-4619e.txt
그리고tcw_mell_upload_lx.txt
diff
잠깐, 각 쌍을 하나씩 수동으로 수행할 필요 없이요 ? 저는 Linux 시스템을 실행하고 있습니다.
답변1
각 파일 쌍의 일치하는 문자열이 항상 동일한 위치에 있다고 가정하면 이 옵션을 제안합니다.
# loop over the files that start with 'cf-'
for f in cf-*.txt; do
# extract the unique "code", e.g 'tcg'
code=$(echo "$f" | cut -d'-' -f5)
# match the looped file with the one that starts with the "code"
echo "diff" *"-${code}"* "${code}"*.txt
# perform your commands, in this case I use an `echo` to show
# how the command `diff` will be executed
done
diff cf-mell-pos-908-tcg-4619e.txt tcg_mell_upload_lx.txt
diff cf-mell-pos-908-tcw-4619e.txt tcw_mell_upload_lx.txt
diff cf-mell-pos-908-usc-4619e.txt usc_mell_upload_lx.txt
diff cf-mell-pos-908-wi_board-4619e.txt wi_board_mell_upload_lx.txt