我正在根据文件中的文件名列表在循环中调用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但这是行不通的。
发布于 2013-08-22 21:24:19
通常,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-22 21:53:48
有很多方法可以解决你的问题。
你可以试试这个,也许不是更好的:
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-22 22:00:30
试试这个:
cat list.txt | tee >(rev | cut -d'.' -f2- | rev > list.out) | xargs gunzip使用AWK修剪.gz
cat list.txt | tee >(awk -F '.' '{$NF="";print}' > list.out) | xargs gunzip使用sed
cat list.txt | tee >(sed 's/\.gz$//' > list.out) | xargs gunziphttps://stackoverflow.com/questions/18381508
复制相似问题