如何编写更新文本文件的脚本?

如何编写更新文本文件的脚本?

我制作了这个脚本:

#PACKAGES.TXT
array2=(
`find . -type f -iname *t?z|awk '{print $1}'|cut -d / -f 3`
)
funzioneZ() {
echo -e " PACKAGE NAME: $i "  
}
array3=(
`find . -type f -iname *t?z|awk '{print $1}'|cut -d / -f 1,2`
)
funzioneA() {
echo -e " PACKAGE LOCATION: $i "  
}
array4=(
`for i in */*txz;do xz -l $i |tail -n 1|cut -d . -f 1|awk '{print $3, "K"}'; done`
)
funzioneB() {
    echo -e " PACKAGE SIZE (compressed): $i "  
}
rm MANIFEST2
for i in ${array2[@]};do funzioneZ $i >> MANIFEST2;done
for i in ${array3[@]};do funzioneA $i >> MANIFEST2;done
for i in ${array4[@]};do funzioneB $i >> MANIFEST2;done

实际结果:

 PACKAGE NAME: pam-1.1.8-x86_64-2mg.txz 
 PACKAGE NAME: tvtime-1.0.2-x86_64-3_SBo.txz 
 PACKAGE LOCATION: ./a 
 PACKAGE LOCATION: ./x 
 PACKAGE SIZE (compressed): 453 
 PACKAGE SIZE (compressed): 606 

但我希望结果看起来像这样:

 PACKAGE NAME: pam-1.1.8-x86_64-2mg.txz 
 PACKAGE LOCATION: ./a
 PACKAGE SIZE (compressed): 453 
 PACKAGE NAME: tvtime-1.0.2-x86_64-3_SBo.txz 
 PACKAGE LOCATION: ./x 
 PACKAGE SIZE (compressed): 606 

我怎样才能做到这一点?

答案1

找到解决方案:干净、简单

for i in ${array1[@]};do echo -e "PACKAGE NAME:$i " >> MANIFEST2 && echo -e "PACKAGE SIZE: `xz -l $i |tail -n 1|cut -d . -f 1|awk '{print $3, "K"}'`" >> PACKAGES.TXT




PACKAGE NAME:a/pam-1.1.8-x86_64-2mg.txz 
PACKAGE SIZE: 453 K
PACKAGE NAME:x/tvtime-1.0.2-x86_64-3_SBo.txz 
PACKAGE SIZE: 606 K

相关内容