我有一个名为 v1 的目录,其中有以下树
v1
├── a.json
├── b.json
├── c.json
├── d.json
├── CRESTReport # this is a directory i.e. v1/CRESTReport
│ ├── crest.json
│ ├── crest1.json
├── Servers # this is a directory i.e. v1/Servers
│ ├── 01 # this is a directory i.e. v1/Servers/01
│ ├── 01.json
│ ├── 02 # this is a directory i.e. v1/Servers/02
│ ├── 02.json
另一个名为 v2 的目录也具有相同的结构和文件集(v2 中是否有任何额外文件并不重要)。对于 v1 中的每个 .json 文件,我需要验证 v2 中是否存在相同的 .json。如果存在,我需要一个单独的输出文件来对每个 .json 文件执行 diff。
已经写好脚本:
#!/usr/bin/env bash
# Provide full path of Config for v1 followed by v2
v1path="$1"
v2path="$2"
for v1File in $(find "$v1path" -name "*.json" -printf '%f\n')
do
v2File=$(find "$v2path" -type f -name $v1File -printf '%f\n')
if [[ $? -eq 0 ]]
then
echo "Doing a diff between v1 $v1File and v2 $v2File"
diff <(find "$v1path" -name $v1File) <(find "$v2path" -name $v2File) > "${v1File}_Diff_Output"
else
echo "Filename $v1File Not Found in v2" > ${v1File}_Missing_In_v2"
fi
done
我在每个文件中得到的输出是:
a.json_Diff_Output
1c1
< /mnt/c/Users/mshah220/AMConfigDataComparison/v1/a.json
---
> /mnt/c/Users/mshah220/AMConfigDataComparison/v2/a.json
b.json_Diff_Output
1c1
< /mnt/c/Users/mshah220/AMConfigDataComparison/v1/b.json
---
> /mnt/c/Users/mshah220/AMConfigDataComparison/v2/b.json
crest.json_Diff_输出
1c1
< /mnt/c/Users/mshah220/AMConfigDataComparison/v1/CRESTReporter/crest.json
---
> /mnt/c/Users/mshah220/AMConfigDataComparison/v2/CRESTReporter/crest.json
相反,我希望每个文件的输出像这样:
4c4
< "amsterVersion" : "6.5.3",
---
> "amsterVersion" : "7.3.0",
Q2) 并且将 v1 中的每个丢失文件写入新目录。我怎样才能将所有丢失的文件写入单个目录?