我在不同的文件夹中有几个同名的 .gz 文件。所以我想解压缩所有这些 .gz 文件并将所有输出文件合并到一个文件中。
问问题
1527 次
3 回答
1
find . -name "xyz.gz"|xargs zcat >output_file
于 2012-10-01T09:06:17.960 回答
1
如果您事先不知道文件的名称,您可能会发现以下脚本很有帮助。您应该将其作为my-script.sh /path/to/search/for/duplicate/names /target/dir/to/create/combined/files
. 它查找给定路径中出现多次的所有文件名,并将它们的内容组合到目标目录中的单个文件中。
#! /bin/bash
path=$1
target=$2
[[ -d $path ]] || { echo 'Path not found' ; exit 1 ; }
[[ -d $target ]] || { echo 'Target not found' ; exit 1; }
find "$path" -name '*.gz' | \
rev | cut -f1 -d/ | rev | \ # remove the paths
sort | uniq -c | \ # count numbers of occurrences
grep -v '^ *1 ' | \ # skip the unique files
while read _num file ; do # process the files in a loop
find -name "$file" -exec zcat {} \; | \ # find the files with the given name and output their content
gzip > "$target/${file##*/}" # gzip the target file
done
于 2012-10-01T09:27:36.253 回答
0
find some/dir -name foo.gz -exec zcat {} \; > output.file
于 2012-10-01T07:37:09.967 回答