0

我根据文件中的文件名列表在循环中调用 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

但这不起作用。

4

3 回答 3

2

通常 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
于 2013-08-22T13:24:18.653 回答
0

有很多方法可以解决您的问题。

你可以试试这个,也许不是更好的一个:

    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
于 2013-08-22T13:53:47.840 回答
-1

尝试这个:

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
于 2013-08-22T14:00:30.020 回答