을 비교하면서 내가 선으로 두 파일 라인을 비교하면서, 즉,이 개 파일배쉬 쉘 스크립트 검사 2 개 파일
파일 1
abc
cde
efg
hij
jkl
이제 파일 2
abc
(*) (*) (*) -- without the braces
efg
(*) hij -- without braces
(*) (*) lmn --- without braces
을 가지고, file1의 첫 번째 줄은 file2의 첫 번째 줄과 만 비교됩니다.
abc ---- abc
cde ---- * * *
,451,515,
때 * *
hij --- (*) hij or jkl --- (*) (*) lmn
hij
을 비교하면서있는 File2의 hij
과 비교해야하며, 다음 행 비교로 이동해야 다른 라인
을 비교를 발견하고 확인 하고, jkl
해야을 부여해야 * lmn
과 비교해야하며 알 수 없습니다. 어느 경우이든 *
또는 * *
을 무시하십시오.
동일한 스크립트를 작성했습니다. 2 파일을 비교, 그러나 *
에 대한 수표를 넣을 수 없습니다.
# 1. Read lines from file1 as string, and file2 as comma-separated array.
while read -r a && IFS=, read -ra b <&3; do
# 2. If both empty lines, continue.
if [[ "$a" == "" && ${#b[@]} == 0 ]]; then
continue
fi
# 3. Start assuming diff.
diff=1
# 4. Loop fields in $b.
for e in ${b[@]}; do
# Compare field in $b with $a, if match then abort.
if [[ "$e" == "$a" ]]; then
diff=0
break
fi
done
# 5. If no match found, print line from $b.
if [[ $diff == 1 ]]; then
# Join array with <space>comma.
line=$(printf ", %s" "${b[@]}")
# Print line, excluding leading <space>comma.
printf "%s\n" "${line:2}"
fi
# Input argument one as file 1 to stdin, and argument two as file 2 to
# file descriptor 3.
done < "$1" 3<"$2"
요구 사항을 명확히 할 수 있습니까? 파일 b의 줄에있는 어떤 단어 (즉,'$ {b [@]} '의 요소가 하나의 별표 ('*')로만 구성되어 있다면, 당신은 전체 라인 쌍? – bgoldst
no .. 파일 b의 줄에 단일 또는 이중 astrix (*)가 있지만 값이 나중에 있으면 file1과 비교해야합니다. 그러나 b 파일의 줄에 3 (최대) (*)가 포함되어 있으면 비교를 위해 두 파일 모두 다음 줄로 이동해야합니다. –
[모든 SO 교환에 동일한 질문을 다시 보내지 마십시오.] (http : // unix. stackexchange.com/questions/179839/bash-shell-scripting-check-while-comparing-2-files) –