我有两组文件.txt和.xml,有各种版本。 文件名及其内容如下: -
filenameXYZ_v1.0.txt
apple
filenameXYZ_v2.0.txt
apple
filenameXYZ_v3.0.txt
orange
filenameXYZ_v4.0.txt
orange
.................................
filenameXYZ_v1.0.xml
"Data of v1.0 and v2.0"
filenameXYZ_v2.0.xml
"Junk"
filenameXYZ_v3.0.xml
"Data of v3.0 and v4.0"
filenameXYZ_v4.0.xml
"Junk"
xml文件中的数据是非冗余的,即如果它们相应的.txt文件具有相同的内容,则只有一个.xml文件将具有真正的“数据”,其他版本将填充“垃圾”。我想让xml文件多余,如: -
filenameXYZ_v1.0.xml
"Data of v1.0 and v2.0"
filenameXYZ_v2.0.xml
"Data of v1.0 and v2.0"
filenameXYZ_v3.0.xml
"Data of v3.0 and v4.0"
filenameXYZ_v4.0.xml
"Data of v3.0 and v4.0"
答案 0 :(得分:0)
for file in filenameXYZ_v?.0.txt
do if [ "$prefile" ] && cmp -s $file $prefile
then cp `basename $prefile txt`xml `basename $file txt`xml
fi
prefile=$file
done