我根据文件中的文件名列表在循环中调用 gunzip 命令。我希望它既解压缩文件又生成文件名列表。
我努力了
for i in `cat $file_name`
do
gunzip $i>>temp.txt
done
和
for i in `cat $file_name`
do
echo `gunzip $i`>>temp.txt
done
但这不起作用。
通常 gunzip 将提取文件并删除.gz
扩展名
for i in `cat $file_name`
do
gunzip $i
echo $i|sed -e 's/\.gz//g' -e 's/\.tgz/.tar/g' >>temp.txt
done
有很多方法可以解决您的问题。
你可以试试这个,也许不是更好的一个:
OUTPUT_TEMP_TXT="temp.txt"
for GFILE in $(cat $file_name)
do
# Because there is only 1 file in a GZIP archive
FILENAME=$(gunzip -v $GFILE 2>&1)
RCODE=$?
if [[ RCODE -eq 0 ]]
then
echo ${FILENAME} | cut -d':' -f1 | sed -e 's/\.gz$//gi' -e 's/\.tgz$/\.tar/gi' >> ${OUTPUT_TEMP_TXT}
else
echo "Can't extract $GFILE" >> ${OUTPUT_TEMP_TXT}
fi
done
尝试这个:
cat list.txt | tee >(rev | cut -d'.' -f2- | rev > list.out) | xargs gunzip
修剪:.gz
_AWK
cat list.txt | tee >(awk -F '.' '{$NF="";print}' > list.out) | xargs gunzip
与sed
:
cat list.txt | tee >(sed 's/\.gz$//' > list.out) | xargs gunzip